简体   繁体   中英

Maven, exclude hamcrest dependency for junit

I excluded hamcrest dependency for junit depdendency in pom.xml. When I compare logs upon running "mvn package" and "mvn dependency:tree" , I do not see any difference before and after exclduing hamcrest dependency.

Here is the portion for excluding the transitive dependency. Where can I find the difference before and after running the exclusion part? I also looked into .m2 directory

<dependencies>
    <dependency>
       <groupId>junit</groupId>
        <artifactId>junit</artifactId>
       <version>${junit.version}</version>
       <scope>test</scope>
       <exclusions>
         </exclusion>
            <groupId> org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
          </exclusion>
      </exclusions>
</dependency>

As Kiril S. stated the shown pom portion is not valid, because of the typo, which should result in an error when executing any task.

The exclusion is wrong since it does match up any dependency declared by junit. Running mvn dependency:tree should show the following:

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ my-app ---
[INFO] com.mycompany.app:my-app:jar:1.0-SNAPSHOT
[INFO] \- junit:junit:jar:4.11:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.3:test

As you see the actual dependency of junit would be

<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>

If you fix that up in your pom the invocation of mvn dependency:tree will result in the expected exclusion.

[INFO] com.mycompany.app:my-app:jar:1.0-SNAPSHOT
[INFO] \- junit:junit:jar:4.11:test
[INFO] ------------------------------------------------------------------------

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM