简体   繁体   English

Maven,排除对junit的hamcrest依赖

[英]Maven, exclude hamcrest dependency for junit

I excluded hamcrest dependency for junit depdendency in pom.xml. 我在pom.xml中排除了junit依赖的hamcrest依赖关系。 When I compare logs upon running "mvn package" and "mvn dependency:tree" , I do not see any difference before and after exclduing hamcrest dependency. 当我比较运行"mvn package""mvn dependency:tree"时的日志时,排除hamcrest依赖关系前后,我看不出任何区别。

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 我也查看了.m2目录

<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. 正如Kiril S.所说,由于打字错误,显示的pom部分无效,执行任何任务时都将导致错误。

The exclusion is wrong since it does match up any dependency declared by junit. 排除是错误的,因为它确实匹配了junit声明的任何依赖项。 Running mvn dependency:tree should show the following: 运行mvn dependency:tree应该显示以下内容:

[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 如您所见,junit的实际依赖关系是

<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. 如果您在pom中解决了该问题,则调用mvn dependency:tree将导致预期的排除。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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