【发布时间】:2015-07-29 21:00:03
【问题描述】:
我们有一个包含十几个子项目的父项目。大多数子项目都有测试,因此它们依赖于 JUnit。我认为将其作为托管依赖项拉到父 pom 中是有意义的:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
在我的一个子项目中 - 仍在清理这个项目 - 我在构建期间需要 JUnit。所以在那个 pom 中我现在有:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
这很好用。 事情崩溃的部分是,该项目还需要构建为具有依赖关系的 jar,使用:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>TestIntegration</finalName>
</configuration>
</plugin>
jar-with-dependencies 缺少 JUnit。请注意,如果我将 JUnit 作为托管依赖项删除,并将其指定为该项目中的正常依赖项,那么一切都会正常构建。
如何将 jar 作为测试范围的托管依赖项放入 jar-with-dependencies?
【问题讨论】: