[英]Specify both jar and test-jar types in Maven dependencies
I have a project called "commons" that contains common includes for both runtime and test. 我有一个名为“commons”的项目,其中包含运行时和测试的常见包含。
In the main project I added a dependency for commons: 在主项目中,我添加了一个公共依赖:
<dependency>
<groupId>com.alexb</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
However the test common files are not included. 但是,不包括测试常用文件。 So I added : 所以我补充说:
<dependency>
<groupId>com.alexb</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
However when type is test-jar, the runtime is not included. 但是当type是test-jar时,不包括运行时。
Unfortunatelly, it seems I cannot include both: 不幸的是,似乎我不能同时包括两者:
<type>jar,test-jar</type>
What can I do to include both? 我可以做些什么来包括两者?
As @khmarbaise mentioned in the comments you should separate your test-jar part project. 正如@khmarbaise在评论中提到的那样,你应该将你的测试罐部分项目分开。
I presume you have in the commons
pom.xml something like this which generates common test-jar. 我认为你在commons
pom.xml中有这样的东西,它产生了常见的测试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>
The problem with this approach is that you don't get the transitive test-scoped dependencies automatically. 此方法的问题在于您不会自动获得传递测试范围的依赖项。
Check this link for more details: 查看此链接了解更多详情:
https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.