我有一个名为“commons”的项目,其中包含运行时和测试的公共(public)包含内容。
在主项目中,我添加了公共(public)依赖项:
<dependency>
<groupId>com.alexb</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
但是不包括测试通用文件。所以我添加了:
<dependency>
<groupId>com.alexb</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
但是,当类型为 test-jar 时,不包括运行时。
不幸的是,我似乎不能同时包含两者:
<type>jar,test-jar</type>
我该怎么做才能将两者都包含在内?
最佳答案
正如 @khmarbaise 在评论中提到的,您应该分离您的 test-jar 部分项目。
我假设您在 commons
pom.xml 中有类似这样的内容,它会生成公共(public)测试 jar。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
这种方法的问题是您无法自动获取可传递的测试范围的依赖项。
查看此链接了解更多详细信息:
https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html
关于java - 在 Maven 依赖项中指定 jar 和 test-jar 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34358907/