Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore/handle reporting on different class with same name #215

Closed
timander opened this issue May 20, 2014 · 3 comments
Closed

Ignore/handle reporting on different class with same name #215

timander opened this issue May 20, 2014 · 3 comments

Comments

@timander
Copy link

I am having trouble using JaCoCo on a multi-module Maven project because some of my transitive dependencies include copies of the same class. The particular offender is org.apache.commons.collections.ArrayStack.

Here are the transitives which include copies of the same classes:
commons-beanutils:commons-beanutils-core:1.7.0
commons-beanutils:commons-beanutils:1.8.0
commons-collections:commons-collections:3.2.1

I tried excluding these, but they are very transitive (when I exclude from one place, they show up somewhere else! I stopped this route after excluding from 9 places.)

From the FAQ: Why do I get the error "Can't add different class with same name"?

For coverage report generation all classes within a group must have unique names. You get this error during report generation if JaCoCo is supplied with multiple different class files with the same name. To fix this remove those duplicate classes or create separate reports or report groups for each version.

I tried adding org.apache.commons.collections.ArrayStack to the excluded classes in the jacoco-maven-plugin, and it appears to generate the correct argLine, but it does not ignore the class.

Here is the argLine passed from the jacoco-maven-plugin:

[INFO] --- jacoco-maven-plugin:0.7.1.201405082137:prepare-agent (pre-unit-test) @ privateLoanIntegration ---
[INFO] surefireArgLine set to -javaagent:c:\\development\\nexus-local-repo\\org\\jacoco\\org.jacoco.agent\\0.7.1.201405082137\\org.jacoco.agent-0.7.1.201405082137-runtime.jar=destfile=C:\\projects\\privateloan\\integration\\target\\jacoco.exec,excludes=org.apache.commons.collections.ArrayStack

Here is the error that fails because of the "Can't add different class with same name" error:

[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.7.1.201405082137:report (post-unit-test) on project privateLoanIntegration: An error has occurred in JaCoCo Test report generation. Error while creating report: Error while analyzing class C:\projects\privateloan\integration\target\classes\services\isl-privateloan-timer-service-42.0-SNAPSHOT.war@WEB-INF/lib/commons-collections-3.2.1.jar@org/apache/commons/collections/ArrayStack.class. Can't add different class with same name: org/apache/commons/collections/ArrayStack -> [Help 1]

I would expect the excludes configuration to work around the duplicate classes:

                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.build.directory}/jacoco.exec</dataFile>
                            <excludes>
                                <exclude>org.apache.commons.collections.ArrayStack</exclude>
                            </excludes>
<outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
                        </configuration>
                    </execution>

Alternatively, it would be nice if it would automatically exclude and produce an ugly warning instead of stop and fail to execute the jacoco-maven-plugin.

Please let me know if I can provide any additional information or clarify circumstances for this issue.

Thanks!
Tim Andersen

@marchof
Copy link
Member

marchof commented May 21, 2014

If it would be the exact same class JaCoCo would silently ignore it.

The excludes property of the reporting tool accepts file names, so it should probably read:

                        <excludes>
                            <exclude>org/apache/commons/collections/ArrayStack.class</exclude>
                        </excludes>

@marchof marchof closed this as completed May 21, 2014
@duckpuppy
Copy link

I know this is closed, but I'm having issues with classes with the same name but in different packages causing this issue. Shouldn't Jacoco handle that? I'm having to exclude some project classes that really should have code coverage measured, and really should be different being in different packages.

To be a bit more specific, I have a multi-module Maven build that I'm using the Jacoco Maven plugin's 'merge' and 'report' goals on to get a unified report on all modules and running into issues when class names are the same in different modules, even though those classes are in module-specific Java packages. Is this related to this issue, or should it be filed separately?

@marchof
Copy link
Member

marchof commented Oct 31, 2014

As long as the classes are in different modules and you create reports separately (or define separate groups within the same report) your scenario should work. Please use our mailing list to discuss your issue: https://groups.google.com/d/forum/jacoco

@jacoco jacoco locked and limited conversation to collaborators Jan 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants