Uploaded image for project: 'Clover'
  1. Clover
  2. CLOV-1471

Maven clover2:setup triggers duplicate class exception

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Medium Medium
    • 3.3.1, 4.0.0
    • None
    • Maven plugin
    • None

      We have several maven projects that have more than one source directory. The non-default directories are added using the build-helper plugin. The clover2:setup goal instruments all source folders, but then sets all non-generated directories as source folders on the maven project. That results in compile errors, since source files are both present in the clover instrumented sources and original location.

      Example:
      java/src << 1. default source folder
      java/src-build << 2. additional source folder
      target/generate-sources/jaxb << 3. generated source folder

      Case (2) is causing problems.

            [CLOV-1471] Maven clover2:setup triggers duplicate class exception

            Owen made changes -
            Workflow Original: New Clover Workflow [ 898107 ] New: New Clover Workflow - Restricted [ 1475087 ]
            Piotr Swiecicki made changes -
            Workflow Original: Clover Workflow [ 896559 ] New: New Clover Workflow [ 898107 ]
            Piotr Swiecicki made changes -
            Status Original: Resolved [ 5 ] New: Closed [ 6 ]
            Piotr Swiecicki made changes -
            Workflow Original: reviewflow [ 637586 ] New: Clover Workflow [ 896559 ]

            Aditya Parikh added a comment - - edited

            Hey Mark,

            Yes it does work in initialize phase as follows:

            <execution>
                                    <phase>initialize</phase>
                                    <goals>
                                        <goal>instrument-test</goal>
                                        <goal>check</goal>
                                        <goal>clover</goal>
                                    </goals>
                                </execution>
            
            

            Thanks

            Aditya Parikh added a comment - - edited Hey Mark, Yes it does work in initialize phase as follows: <execution> <phase> initialize </phase> <goals> <goal> instrument-test </goal> <goal> check </goal> <goal> clover </goal> </goals> </execution> Thanks

            Hi Aditya,

            I think that this is caused by a fact that you're using the clover2:instrument instead of the clover2:setup goal. The clover2:instrument forks a custom build life cycle and in this build cycle it performs instrumentation in the 'validate' phase. Due to a fact that your 'add-source' goal is bound to the generate-sources phase, the build-helper-maven-plugin runs after Clover instead of before.

            I suggest to use clover2:setup bounded to the validate or initialize phase (i.e. before the generate-sources one).

            Cheers
            Marek

            Marek Parfianowicz added a comment - Hi Aditya, I think that this is caused by a fact that you're using the clover2:instrument instead of the clover2:setup goal. The clover2:instrument forks a custom build life cycle and in this build cycle it performs instrumentation in the 'validate' phase. Due to a fact that your 'add-source' goal is bound to the generate-sources phase, the build-helper-maven-plugin runs after Clover instead of before. I suggest to use clover2:setup bounded to the validate or initialize phase (i.e. before the generate-sources one). Cheers Marek

            Aditya Parikh added a comment - - edited

            I am facing similar issue for maven-clover2-plugin version 4.0.0. Here's how we are using the build-helper-maven-plugin

            <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>build-helper-maven-plugin</artifactId>
                            <version>1.9.1</version>
                            <executions>
                                <execution>
                                    <id>add-shared-source</id>
                                    <phase>generate-sources</phase>
                                    <goals>
                                        <goal>add-source</goal>
                                    </goals>
                                    <configuration>
                                        <sources>
                                            <source>../SomeOtherModule1/src/main/java/com</source>
                                            <source>../SomeOtherModule2/src/main/java/com</source>
                                            <source>../SomeOtherModule3/src/main/java/com</source>
                                        </sources>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
            

            and this is how we are using the clover2 plugin in a build profile:

                                <plugin>
                                    <groupId>com.atlassian.maven.plugins</groupId>
                                    <artifactId>maven-clover2-plugin</artifactId>
                                    <version>4.0.0</version>
                                    <configuration combine.self="override">
                                        <targetPercentage>${code_coverage_target}</targetPercentage>
                                        <licenseLocation>${clover_license_location}</licenseLocation>
                                    </configuration>
                                    <executions>
                                        <execution>
                                            <phase>verify</phase>
                                            <goals>
                                                <goal>instrument-test</goal>
                                                <goal>check</goal>
                                                <goal>clover</goal>
                                            </goals>
                                        </execution>
                                    </executions>
                                </plugin>
            

            without the clover plugin, the build compiles fine. but after adding the clover plugin, we get several errors saying duplicate classes found.

            Am I missing something here ?

            Aditya Parikh added a comment - - edited I am facing similar issue for maven-clover2-plugin version 4.0.0. Here's how we are using the build-helper-maven-plugin <plugin> <groupId> org.codehaus.mojo </groupId> <artifactId> build-helper-maven-plugin </artifactId> <version> 1.9.1 </version> <executions> <execution> <id> add-shared-source </id> <phase> generate-sources </phase> <goals> <goal> add-source </goal> </goals> <configuration> <sources> <source> ../SomeOtherModule1/src/main/java/com </source> <source> ../SomeOtherModule2/src/main/java/com </source> <source> ../SomeOtherModule3/src/main/java/com </source> </sources> </configuration> </execution> </executions> </plugin> and this is how we are using the clover2 plugin in a build profile: <plugin> <groupId> com.atlassian.maven.plugins </groupId> <artifactId> maven-clover2-plugin </artifactId> <version> 4.0.0 </version> <configuration combine.self= "override" > <targetPercentage> ${code_coverage_target} </targetPercentage> <licenseLocation> ${clover_license_location} </licenseLocation> </configuration> <executions> <execution> <phase> verify </phase> <goals> <goal> instrument-test </goal> <goal> check </goal> <goal> clover </goal> </goals> </execution> </executions> </plugin> without the clover plugin, the build compiles fine. but after adding the clover plugin, we get several errors saying duplicate classes found. Am I missing something here ?

            Hi bbusjaeger, I intend to release Clover 4.0.1 at the end of next week, so in case I would have to code some fixes for this bug, I need to get a feedback from you on the Tuesday (26.08) the latest. I'd be very grateful if you could have a look at my questions posted in previous comments. Cheers!

            Marek Parfianowicz added a comment - Hi bbusjaeger , I intend to release Clover 4.0.1 at the end of next week, so in case I would have to code some fixes for this bug, I need to get a feedback from you on the Tuesday (26.08) the latest. I'd be very grateful if you could have a look at my questions posted in previous comments. Cheers!

            One more thing: can you tell whether you're using a parallel compilation in Maven?

            I'm asking because Clover does not support parallel builds - it fails when multiple processes are trying to write to the same clover.db file at the same time.

            Marek Parfianowicz added a comment - One more thing: can you tell whether you're using a parallel compilation in Maven? I'm asking because Clover does not support parallel builds - it fails when multiple processes are trying to write to the same clover.db file at the same time.

            In case running 'mvn -X' will not reveal more details, then I suggest running the CloverInstr tool manually on your sources generated by Avro. Thanks to this we will check whether there is a problem with running an instrumentation (for instance, some code construct which Clover cannot correctly parse). In case it succeeds, then we'll know that it's a problem with the maven-clover2-plugin.

            How to use CloverInstr:

            https://confluence.atlassian.com/display/CLOVER/CloverInstr

            Marek Parfianowicz added a comment - In case running 'mvn -X' will not reveal more details, then I suggest running the CloverInstr tool manually on your sources generated by Avro. Thanks to this we will check whether there is a problem with running an instrumentation (for instance, some code construct which Clover cannot correctly parse). In case it succeeds, then we'll know that it's a problem with the maven-clover2-plugin. How to use CloverInstr: https://confluence.atlassian.com/display/CLOVER/CloverInstr

              mparfianowicz Marek Parfianowicz
              62751354167d Benjamin Busjaeger
              Affected customers:
              0 This affects my team
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: