Fail build if classpath contains duplicates 08/50908/13
authorMichael Vorburger <vorburger@redhat.com>
Mon, 23 Jan 2017 21:41:14 +0000 (22:41 +0100)
committerStephen Kitt <skitt@redhat.com>
Wed, 8 Nov 2017 16:53:36 +0000 (16:53 +0000)
duplicate-finder-maven-plugin fails build if duplicate classpath entries
see https://github.com/basepom/duplicate-finder-maven-plugin/

This is currently not enforced, but projects opt-in to this quality via:

  <properties><duplicate-finder.skip>false

FTR: There are a few other tools in this space, incl. e.g.
http://www.mojohaus.org/extra-enforcer-rules/banDuplicateClasses.html
and http://tattletale.jboss.org/ and http://jhades.github.io, but
duplicate-finder-maven-plugin fits best here.

See https://git.opendaylight.org/gerrit/#/c/50851/ for a related util.

Bug: 7662
Change-Id: I79142549ba7c739ce39285d35f179172d7b099a6
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
features-test/pom.xml
features/odl-akka-system-2.5/pom.xml
karaf-util/pom.xml
karaf/opendaylight-karaf-resources/pom.xml
odlparent-lite/pom.xml
odlparent/pom.xml

index 7056b96ebb6b39354f5ff993854009786e555c4c..027bf176b5e5f08ba6863365ec0a7b1e47da2ba0 100644 (file)
             <groupId>org.opendaylight.odlparent</groupId>
             <artifactId>opendaylight-karaf-empty</artifactId>
             <type>zip</type>
+            <exclusions>
+              <exclusion>
+                <groupId>*</groupId>
+                <artifactId>*</artifactId>
+              </exclusion>
+            </exclusions>
         </dependency>
         <!-- BEWARE of adding additional dependencies here...
              It will cause weird issues e.g. in integration/distribution/features/repos/distribution -->
index c223c29d237b1675ca8b571fee011a19fdb28457..d1b0ac891b9ca326d33834270dba3cf115d36b44 100644 (file)
         <dependency>
             <groupId>com.typesafe.akka</groupId>
             <artifactId>akka-osgi_2.12</artifactId>
+            <exclusions>
+              <exclusion>
+                <groupId>org.osgi</groupId>
+                <artifactId>org.osgi.compendium</artifactId>
+              </exclusion>
+            </exclusions>
         </dependency>
     </dependencies>
 
index 82bf29a33286a10342ede0e750df1c259f108045..9669030ca4822de5748cf491d1ddd86d2245e40f 100644 (file)
             <artifactId>wagon-http</artifactId>
             <version>2.10</version>
             <scope>compile</scope>
+            <exclusions>
+              <exclusion>
+                <!-- because it conflicts with org.slf4j:jcl-over-slf4j -->
+                <groupId>commons-logging</groupId>
+                <artifactId>commons-logging</artifactId>
+              </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.ops4j.pax.url</groupId>
index 9c864e3c2bbccce69232cee58bd0533607bc2a76..4b42a8ae5735680a40726e5583e95063cf973ecc 100644 (file)
   <description>Resources for opendaylight-karaf</description>
   <packaging>jar</packaging>
   <name>ODL :: odlparent :: ${project.artifactId}</name>
+  <properties>
+    <!-- There are a lot of duplicate classes in the dependencies below, but this is not a real issue,
+         because this is not a real Java artifact; it's just packaging.  (TODO: Ideally, this artifact should
+         just have odlparent-lite not odlparent as parent, and not run Java static code analysis tools.)
+      -->
+    <duplicate-finder.skip>true</duplicate-finder.skip>
+  </properties>
   <dependencies>
     <dependency>
       <groupId>org.apache.karaf.features</groupId>
index a83e17e0be6c32c31eab75fdb1e76f89b1b1b40b..78519fdc50be4aeda29657ccc8556ac62c3a7663 100644 (file)
         <maven.site.skip>true</maven.site.skip>
         <invoker.skip>true</invoker.skip>
         <enforcer.skip>true</enforcer.skip>
+        <duplicate-finder.skip>true</duplicate-finder.skip>
         <mdsal.skip.verbose>true</mdsal.skip.verbose> <!-- Bug 6236 -->
         <gitid.skip>true</gitid.skip>
       </properties>
index ccd2a7c87bc80a16cb39ff7193efd91ffa15ee51..8f7419e45f5c89f94f6d98bc067d088fbe361172 100644 (file)
     <!-- Note: This list should match jacoco-maven-plugin's exclusion list below -->
     <sonar.exclusions>**/gen/**,**/generated-sources/**,**/generated-test-sources/**,**/yang-gen/**,**/yang-gen-config/**,**/yang-gen-sal/**,**/yang-gen-code/**,**/pax/**</sonar.exclusions>
 
-    <pmd.cpd.fail>false</pmd.cpd.fail>
+    <!-- Opt-in code quality checks -->
+    <pmd.cpd.fail>false</pmd.cpd.fail>                  <!-- Copy/paste detection -->
+    <duplicate-finder.skip>true</duplicate-finder.skip> <!-- Classpath duplicates -->
   </properties>
 
   <dependencyManagement>
         <groupId>org.ops4j.pax.url</groupId>
         <artifactId>pax-url-wrap</artifactId>
         <version>2.5.3</version>
+        <exclusions>
+          <exclusion>
+            <!-- because pax-url-aether already includes a different version of classes in this artifact -->
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-commons</artifactId>
+          </exclusion>
+        </exclusions>
       </dependency>
 
       <dependency>
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.basepom.maven</groupId>
+        <artifactId>duplicate-finder-maven-plugin</artifactId>
+        <version>1.2.1</version>
+        <executions>
+          <execution>
+            <id>find-duplicate-classpath-entries</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>check</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+            <!-- https://github.com/basepom/duplicate-finder-maven-plugin/wiki -->
+            <failBuildInCaseOfConflict>false</failBuildInCaseOfConflict>
+            <failBuildInCaseOfDifferentContentConflict>true</failBuildInCaseOfDifferentContentConflict>
+            <failBuildInCaseOfEqualContentConflict>false</failBuildInCaseOfEqualContentConflict>
+            <printEqualFiles>false</printEqualFiles>
+            <quiet>true</quiet>
+            <!-- In addition to https://github.com/basepom/duplicate-finder-maven-plugin/wiki/Default%20ignored%20elements,
+                 as explained on https://github.com/basepom/duplicate-finder-maven-plugin/wiki/Ignoring%20Dependencies%20and%20Resources,
+                 we use resources not dependencies (see https://github.com/basepom/duplicate-finder-maven-plugin/wiki/Classpath%20Exceptions)
+                 also ignore: -->
+            <ignoredResourcePatterns>
+              <ignoredResourcePattern>org/opendaylight/blueprint/autowire.xml$</ignoredResourcePattern>
+              <ignoredResourcePattern>OSGI-OPT/bnd.bnd$</ignoredResourcePattern>
+              <ignoredResourcePattern>README.*$</ignoredResourcePattern>
+              <ignoredResourcePattern>.*\.html$</ignoredResourcePattern>
+              <ignoredResourcePattern>reference.conf</ignoredResourcePattern>
+            </ignoredResourcePatterns>
+            <ignoredDependencies>
+              <ignoredDependency>
+                <groupId>org.slf4j</groupId>
+                <artifactId>slf4j-simple</artifactId>
+              </ignoredDependency>
+              <ignoredDependency>
+                <groupId>org.opendaylight.odlparent</groupId>
+                <artifactId>opendaylight-karaf-empty</artifactId>
+              </ignoredDependency>
+            </ignoredDependencies>
+        </configuration>
+      </plugin>
       <plugin>
         <artifactId>maven-dependency-plugin</artifactId>
       </plugin>