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

Can I check classes with the same class name in one project? #54

Closed
chanjetsdp opened this issue Jan 26, 2022 · 1 comment
Closed

Can I check classes with the same class name in one project? #54

chanjetsdp opened this issue Jan 26, 2022 · 1 comment

Comments

@chanjetsdp
Copy link

chanjetsdp commented Jan 26, 2022

I expect failure when there are two classes with same name App in project.

   target/classes/com/mycompany/app/App.class
   target/classes/com/mycompany/app2/App.class

my-app-banDuplicateClasses.tar.gz

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>my-app</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
        <plugin>
            <groupId>org.basepom.maven</groupId>
            <artifactId>duplicate-finder-maven-plugin</artifactId>
            <version>1.5.1</version>
            <executions>
                <execution>
                    <id>default</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>

<configuration>
    <skip>false</skip>
    <quiet>false</quiet>
    <checkCompileClasspath>true</checkCompileClasspath>
    <checkRuntimeClasspath>true</checkRuntimeClasspath>
    <checkTestClasspath>true</checkTestClasspath>
    <failBuildInCaseOfDifferentContentConflict>false</failBuildInCaseOfDifferentContentConflict>
    <failBuildInCaseOfEqualContentConflict>false</failBuildInCaseOfEqualContentConflict>
    <failBuildInCaseOfConflict>false</failBuildInCaseOfConflict>
    <printEqualFiles>false</printEqualFiles>
    <preferLocal>true</preferLocal>

    <!-- Version 1.1.1+ -->
    <includeBootClasspath>false</includeBootClasspath>
    <bootClasspathProperty>sun.boot.class.path</bootClasspathProperty>
    <!-- Version 1.1.1+ -->


    <!-- Version 1.2.0+ -->
    <includePomProjects>false</includePomProjects>
    <!-- Version 1.2.0+ -->
</configuration>

        </plugin>
 </plugins>
  </build>
</project>

find target/classes

target/classes
target/classes/com
target/classes/com/mycompany
target/classes/com/mycompany/app
target/classes/com/mycompany/app/App.class
target/classes/com/mycompany/app/App1.class
target/classes/com/mycompany/app2
target/classes/com/mycompany/app2/App2.class
target/classes/com/mycompany/app2/App.class

mvn -X clean compile -DskipTests verify

[INFO] --- duplicate-finder-maven-plugin:1.5.1:check (default) @ my-app ---
[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=101007, ConflictMarker.markTime=91454, ConflictMarker.nodeCount=72, ConflictIdSorter.graphTime=39531, ConflictIdSorter.topsortTime=32313, ConflictIdSorter.conflictIdCount=33, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=1151037, ConflictResolver.conflictItemCount=65, DefaultDependencyCollector.collectTime=103022165, DefaultDependencyCollector.transformTime=1443280}
[DEBUG] org.basepom.maven:duplicate-finder-maven-plugin:jar:1.5.1
[DEBUG]    org.apache.maven:maven-plugin-api:jar:3.0:compile
[DEBUG]    org.apache.maven:maven-model:jar:3.0:compile
[DEBUG]       org.codehaus.plexus:plexus-utils:jar:2.0.4:compile
[DEBUG]    org.apache.maven:maven-artifact:jar:3.0:compile
[DEBUG]    org.apache.maven:maven-core:jar:3.0:compile
[DEBUG]       org.apache.maven:maven-settings:jar:3.0:compile
[DEBUG]       org.apache.maven:maven-settings-builder:jar:3.0:compile
[DEBUG]       org.apache.maven:maven-repository-metadata:jar:3.0:compile
[DEBUG]       org.apache.maven:maven-model-builder:jar:3.0:compile
[DEBUG]       org.apache.maven:maven-aether-provider:jar:3.0:runtime
[DEBUG]       org.sonatype.aether:aether-impl:jar:1.7:compile
[DEBUG]          org.sonatype.aether:aether-spi:jar:1.7:compile
[DEBUG]       org.sonatype.aether:aether-api:jar:1.7:compile
[DEBUG]       org.sonatype.aether:aether-util:jar:1.7:compile
[DEBUG]       org.codehaus.plexus:plexus-interpolation:jar:1.14:compile
[DEBUG]       org.codehaus.plexus:plexus-classworlds:jar:2.2.3:compile
[DEBUG]       org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[DEBUG]       org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[DEBUG]          org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[DEBUG]    com.google.guava:guava:jar:28.1-jre:compile
[DEBUG]       com.google.guava:failureaccess:jar:1.0.1:compile
[DEBUG]       com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[DEBUG]       org.checkerframework:checker-qual:jar:2.8.1:compile
[DEBUG]       com.google.errorprone:error_prone_annotations:jar:2.3.2:compile
[DEBUG]       com.google.j2objc:j2objc-annotations:jar:1.3:compile
[DEBUG]       org.codehaus.mojo:animal-sniffer-annotations:jar:1.18:compile
[DEBUG]    net.jcip:jcip-annotations:jar:1.0:compile
[DEBUG]    com.google.code.findbugs:jsr305:jar:3.0.2:compile
[DEBUG]    org.slf4j:slf4j-api:jar:1.7.28:compile
[DEBUG]    org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[DEBUG]    org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:runtime
[DEBUG]    com.fasterxml.staxmate:staxmate:jar:2.2.1:compile
[DEBUG] Created new class realm plugin>org.basepom.maven:duplicate-finder-maven-plugin:1.5.1
[DEBUG] Importing foreign packages into class realm plugin>org.basepom.maven:duplicate-finder-maven-plugin:1.5.1
[DEBUG]   Imported:  < maven.api
[DEBUG] Populating class realm plugin>org.basepom.maven:duplicate-finder-maven-plugin:1.5.1
[DEBUG]   Included: org.basepom.maven:duplicate-finder-maven-plugin:jar:1.5.1
[DEBUG]   Included: org.codehaus.plexus:plexus-utils:jar:2.0.4
[DEBUG]   Included: org.sonatype.aether:aether-util:jar:1.7
[DEBUG]   Included: org.codehaus.plexus:plexus-interpolation:jar:1.14
[DEBUG]   Included: org.codehaus.plexus:plexus-component-annotations:jar:1.5.5
[DEBUG]   Included: org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3
[DEBUG]   Included: org.sonatype.plexus:plexus-cipher:jar:1.4
[DEBUG]   Included: com.google.guava:guava:jar:28.1-jre
[DEBUG]   Included: com.google.guava:failureaccess:jar:1.0.1
[DEBUG]   Included: com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava
[DEBUG]   Included: org.checkerframework:checker-qual:jar:2.8.1
[DEBUG]   Included: com.google.errorprone:error_prone_annotations:jar:2.3.2
[DEBUG]   Included: com.google.j2objc:j2objc-annotations:jar:1.3
[DEBUG]   Included: org.codehaus.mojo:animal-sniffer-annotations:jar:1.18
[DEBUG]   Included: net.jcip:jcip-annotations:jar:1.0
[DEBUG]   Included: com.google.code.findbugs:jsr305:jar:3.0.2
[DEBUG]   Included: org.codehaus.woodstox:stax2-api:jar:3.1.4
[DEBUG]   Included: org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1
[DEBUG]   Included: com.fasterxml.staxmate:staxmate:jar:2.2.1
[DEBUG] Configuring mojo org.basepom.maven:duplicate-finder-maven-plugin:1.5.1:check from plugin realm ClassRealm[plugin>org.basepom.maven:duplicate-finder-maven-plugin:1.5.1, parent: sun.misc.Launcher$AppClassLoader@4e25154f]
[DEBUG] Configuring mojo 'org.basepom.maven:duplicate-finder-maven-plugin:1.5.1:check' with basic configurator -->
[DEBUG]   (f) bootClasspathProperty = sun.boot.class.path
[DEBUG]   (f) checkCompileClasspath = true
[DEBUG]   (f) checkRuntimeClasspath = true
[DEBUG]   (f) checkTestClasspath = true
[DEBUG]   (f) failBuildInCaseOfConflict = false
[DEBUG]   (f) failBuildInCaseOfDifferentContentConflict = false
[DEBUG]   (f) failBuildInCaseOfEqualContentConflict = false
[DEBUG]   (f) includeBootClasspath = false
[DEBUG]   (f) includePomProjects = false
[DEBUG]   (f) preferLocal = true
[DEBUG]   (f) printEqualFiles = false
[DEBUG]   (f) project = MavenProject: com.mycompany.app:my-app:1.0-SNAPSHOT @ /Users/rock/work/code/cc/my-app/pom.xml
[DEBUG]   (f) quiet = false
[DEBUG]   (f) resultFile = /Users/rock/work/code/cc/my-app/target/duplicate-finder-result.xml
[DEBUG]   (f) resultFileMinClasspathCount = 2
[DEBUG]   (f) skip = false
[DEBUG]   (f) useDefaultClassIgnoreList = true
[DEBUG]   (f) useDefaultResourceIgnoreList = true
[DEBUG]   (f) useResultFile = true
[DEBUG] -- end configuration --
[INFO] Checking compile classpath
[INFO] Checking runtime classpath
[DEBUG] Cache hit for '/Users/rock/work/code/cc/my-app/target/classes'
[INFO] Checking test classpath
[DEBUG] Ignoring META-INF/MANIFEST.MF, MANIFEST.MF is not a class file
[DEBUG] Ignoring LICENSE.txt, LICENSE.txt is not a class file
[DEBUG] Ignoring 'META-INF/MANIFEST.MF' (matches ^META-INF/.*)
[DEBUG] Ignoring 'LICENSE.txt' (matches .*license(\.txt)?$)
[DEBUG] Ignoring 'junit.extensions.ActiveTestSuite$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'junit.extensions.TestSetup$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'junit.extensions.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'junit.framework.JUnit4TestAdapterCache$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'junit.framework.TestResult$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'junit.framework.TestSuite$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'junit.framework.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'junit.runner.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'junit.textui.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'org.junit.ComparisonFailure$ComparisonCompactor' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.Test$None' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.ParallelComputer$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.categories.Categories$CategoryFilter' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.categories.Categories$ExcludeCategory' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.categories.Categories$IncludeCategory' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.max.MaxCore$1$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.max.MaxCore$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.max.MaxHistory$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.max.MaxHistory$RememberingListener' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.max.MaxHistory$TestComparator' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.results.ResultMatchers$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.results.ResultMatchers$2' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.results.ResultMatchers$3' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.theories.PotentialAssignment$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.theories.PotentialAssignment$CouldNotGenerateValueException' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.theories.Theories$TheoryAnchor$1$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.theories.Theories$TheoryAnchor$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.theories.Theories$TheoryAnchor$2' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.theories.Theories$TheoryAnchor' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.theories.internal.AllMembersSupplier$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.experimental.theories.internal.AllMembersSupplier$MethodParameterValue' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.internal.MethodSorter$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.internal.MethodSorter$2' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.internal.requests.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'org.junit.internal.runners.JUnit38ClassRunner$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.internal.runners.JUnit38ClassRunner$OldTestClassAdaptingListener' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.internal.runners.JUnit4ClassRunner$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.internal.runners.JUnit4ClassRunner$2' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.internal.runners.MethodRoadie$1$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.internal.runners.MethodRoadie$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.internal.runners.MethodRoadie$2' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.internal.runners.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'org.junit.internal.runners.statements.FailOnTimeout$StatementThread' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.matchers.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'org.junit.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'org.junit.rules.ErrorCollector$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.rules.ExpectedException$ExpectedExceptionStatement' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.rules.ExternalResource$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.rules.TestWatcher$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.rules.TestWatchman$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.rules.Verifier$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.Computer$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.Request$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.Result$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.Result$Listener' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.manipulation.Filter$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.manipulation.Filter$2' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.manipulation.Filter$3' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.manipulation.Sorter$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.manipulation.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'org.junit.runner.notification.RunNotifier$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.notification.RunNotifier$2' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.notification.RunNotifier$3' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.notification.RunNotifier$4' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.notification.RunNotifier$5' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.notification.RunNotifier$6' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.notification.RunNotifier$7' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.notification.RunNotifier$SafeNotifier' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runner.notification.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'org.junit.runner.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring 'org.junit.runners.BlockJUnit4ClassRunner$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runners.Parameterized$Parameter' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runners.Parameterized$Parameters' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runners.Parameterized$TestClassRunnerForParameters' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runners.ParentRunner$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runners.ParentRunner$2' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runners.ParentRunner$3' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runners.ParentRunner$4' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runners.Suite$SuiteClasses' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runners.model.FrameworkMethod$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.junit.runners.package-info' (matches ^(.*\.)?package-info$)
[DEBUG] Ignoring META-INF/MANIFEST.MF, MANIFEST.MF is not a class file
[DEBUG] Ignoring LICENSE.txt, LICENSE.txt is not a class file
[DEBUG] Ignoring 'META-INF/MANIFEST.MF' (matches ^META-INF/.*)
[DEBUG] Ignoring 'LICENSE.txt' (matches .*license(\.txt)?$)
[DEBUG] Ignoring 'org.hamcrest.Condition$1' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.hamcrest.Condition$Matched' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.hamcrest.Condition$NotMatched' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.hamcrest.Condition$Step' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.hamcrest.Description$NullDescription' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.hamcrest.core.CombinableMatcher$CombinableBothMatcher' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Ignoring 'org.hamcrest.core.CombinableMatcher$CombinableEitherMatcher' (matches ^(.*\.)?.*\$.*$)
[DEBUG] Cache hit for '/Users/rock/work/code/cc/my-app/target/classes'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.208 s
[INFO] Finished at: 2022-01-26T13:21:10+08:00
[INFO] ------------------------------------------------------------------------

@chanjetsdp chanjetsdp changed the title Can I check duplicate classes that have the same name in one project? Can I check classes with the same class name in one project? Jan 26, 2022
@hgschmie
Copy link
Contributor

hgschmie commented Apr 5, 2022

Hi,

thank you for filing an issue here. The plugin only detects real duplicates (classes with the same package and class name). Your example (com.mycompany.app.App and com.mycompany.app2.App) are not considered duplicates because they do not share the same package name. For the JVM, these are two distinct classes on the classpath and therefore not a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants