Forbid use of mockito-all via a new maven-enforcer-plugin rule 44/50844/4
authorMichael Vorburger <vorburger@redhat.com>
Mon, 23 Jan 2017 16:31:37 +0000 (17:31 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 21 Feb 2017 10:58:44 +0000 (10:58 +0000)
mockito-all is bad, because it includes other libs (non-shaded), they
never intended it to be used from system with transitive dependency
management such as Maven; it can cause issues incl. fix
NoSuchMethodError: org.hamcrest.Matcher ...

see
http://maven.apache.org/enforcer/enforcer-rules/bannedDependencies.html

We'll remove mockito-all from dependencyManagement a little later.

Bug 7662 related
Change-Id: Id0da73a875cbb6de481782db1ccaadd6ac54ea6f
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
odlparent/pom.xml

index b1df862a79bc98092f0af34ce7c2934f6cf524c8..70a166454ff9052082ebb1ffcb41bfd8df727f51 100644 (file)
          <version>1.3.0</version>
          <scope>test</scope>
       </dependency>
+      <!-- Bug 7662: TODO eventually remove mockito-all, because its use is now forbidden via a new rule of maven-enforcer-plugin below
+                     It wasn't immediately removed together with the introduction of the maven-enforcer-plugin, because while we transition
+                     to replace all uses of mockito-all by mockito-core in all of ODL downstream projects, its much clearer to get a
+                     maven-enforcer-plugin violation message than suddenly a confusing 'dependencies.dependency.version' for org.mockito:mockito-all:jar is missing  -->
       <dependency>
         <groupId>org.mockito</groupId>
         <!-- Bug 7662: @deprecated Do *NOT* use mockito-all, but *ALWAYS* only mockito-core; this should be removed, and non-usage enforced! -->
     </pluginManagement>
 
     <plugins>
+      <plugin>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>enforce-banned-dependencies</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <bannedDependencies>
+                  <message>Please always use mockito-core instead of mockito-all (https://bugs.opendaylight.org/show_bug.cgi?id=7662)</message>
+                  <excludes>
+                    <exclude>org.mockito:mockito-all</exclude>
+                  </excludes>
+                </bannedDependencies>
+              </rules>
+              <fail>true</fail>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
       <plugin>
         <artifactId>maven-dependency-plugin</artifactId>
       </plugin>