我有一个父pom A,有孩子pom B,C和D.在B,C和D中,我有相同类型的依赖项。
即 父Pom
<artifactID>blah</artifactID>
<modules>
<module>B</module>
<module>C</module>
<module>D</module>
</modules>
小孩Pom
<dependencies>
<dependency>
.
.
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>
到目前为止,我已尝试编辑插件 - surefire,但在尝试排除子poms的测试范围时无效。
我的问题是,是否有办法向父pom添加配置文件,以排除所有子poms类型为test-jar的所有依赖项。 感谢
答案 0 :(得分:0)
由于您尝试更新test
范围中的路径,因此您可以挂钩实际负责构建测试类路径的maven-surfire-plugin
并排除不需要的依赖项或添加新的依赖项。因此,如果您希望每个模块应用此限制,您可以将以下条目添加到子poms,例如对于 B :
<project>
...
<artifactId>B</artifactId>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExclude>${undesired-dependency-groupId}:${undesired-dependency-artifactId}</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
或者,如果您希望所有子模块继承此限制 ,请在父pom中定义基于配置文件的插件:
<project>
...
<artifactId>A</artifactId>
<module>B</module>
<module>C</module>
<module>D</module>
...
<profiles>
<profile>
<id>custom-test-goal</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExclude>${undesired-dependency-groupId}:${undesired-dependency-artifactId}</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
</project>