简体   繁体   English

将 Junit 从战争中排除; 保留用于单元测试

[英]Exclude Junit from War; Keep for Unit Tests

I have a Java project that builds a war.我有一个构建战争的 Java 项目。 junit-4.13.2.jar is being included in the war as a transitive dependency. junit-4.13.2.jar 作为传递依赖被包含在战争中。 I'd like to exclude the jar from the war, but I still need to have the jar for running tests.我想将 jar 从战争中排除,但我仍然需要 jar 来运行测试。

My build.gradle looks like:我的 build.gradle 看起来像:

dependencies {
    ...
    testCompile group: 'junit', name: 'junit'
    ...
}

configurations.all {
    exclude group: "org.apache.logging.log4j", module: "log4j-core"
}

Using this config, I can still run my tests, but the jar still ends up in the war.使用这个配置,我仍然可以运行我的测试,但是 jar 仍然在战争中结束。

As you already state that its because of transitive dependency from a compile/runtime dependency - the fix would be to exclude junit from the same正如您已经 state 那样,它是因为来自编译/运行时依赖项的传递依赖 - 修复方法是排除 junit

implementation ('g:a:v') {
  exclude group: 'junit', module: 'junit'
}

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

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