在运行时范围内包含 test-jar
including test-jar in the runtime scope
我有一个 war
项目,在它的 test-jar
中,除了 jUnit 测试用例之外,我们还有对邻居系统的模拟(例如,角色和用户管理系统).
我们有一个名为 mocking
的 Maven 配置文件,它将 test-jar
依赖项添加到 war
-项目,位于 runtime
,以便开发人员可以使用模拟,但是不会因生产错误而结束。
<profile>
<id>mocking</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>runtime</scope>
</dependency>
...
不是很干净,我知道,但我们不希望只用一堆模拟类来制作另一个工件,到目前为止它在 Maven 3.3.9 上运行良好。
现在我们需要 Maven 3.5.0 的功能,所以我更新到最新的 Maven 3.6.2 并得到以下错误:
The project com.my-project:web:0.0.1-SNAPSHOT has 1 error:
'dependencies.dependency.[com.my-project:web:0.0.1-SNAPSHOT]' for com.my-project:web:0.0.1-SNAPSHOT is referencing itself.
这是一种临界情况。
恕我直言,并且由于依赖关系在 runtime
范围内,因此应该允许。
这是一个错误吗?
谁能想出更好的方法来实现这一点?
非常感谢
迈克尔
更新 20191125:
Without full pom files or at least an example which looks very like your original projects it's hard to guess....
这里有一个小的 pom 文件来重现问题:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.project</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
使用该文件,仅此而已,mvn compile
适用于 v3.3.9,但适用于 v3.6.2
如果您使用正常设置创建 test-jar
,这意味着 test-jar
是作为您常用工件的补充工件创建的,这些工件需要彼此区分,必须通过以下方式实现使用 <classifier>tests</classifier>
。
我有一个 war
项目,在它的 test-jar
中,除了 jUnit 测试用例之外,我们还有对邻居系统的模拟(例如,角色和用户管理系统).
我们有一个名为 mocking
的 Maven 配置文件,它将 test-jar
依赖项添加到 war
-项目,位于 runtime
,以便开发人员可以使用模拟,但是不会因生产错误而结束。
<profile>
<id>mocking</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>runtime</scope>
</dependency>
...
不是很干净,我知道,但我们不希望只用一堆模拟类来制作另一个工件,到目前为止它在 Maven 3.3.9 上运行良好。
现在我们需要 Maven 3.5.0 的功能,所以我更新到最新的 Maven 3.6.2 并得到以下错误:
The project com.my-project:web:0.0.1-SNAPSHOT has 1 error:
'dependencies.dependency.[com.my-project:web:0.0.1-SNAPSHOT]' for com.my-project:web:0.0.1-SNAPSHOT is referencing itself.
这是一种临界情况。
恕我直言,并且由于依赖关系在 runtime
范围内,因此应该允许。
这是一个错误吗?
谁能想出更好的方法来实现这一点?
非常感谢
迈克尔
更新 20191125:
Without full pom files or at least an example which looks very like your original projects it's hard to guess....
这里有一个小的 pom 文件来重现问题:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.project</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
使用该文件,仅此而已,mvn compile
适用于 v3.3.9,但适用于 v3.6.2
如果您使用正常设置创建 test-jar
,这意味着 test-jar
是作为您常用工件的补充工件创建的,这些工件需要彼此区分,必须通过以下方式实现使用 <classifier>tests</classifier>
。