从父pom中删除子pom的maven依赖性

从父pom中删除子pom的maven依赖性,maven,dependencies,pom.xml,Maven,Dependencies,Pom.xml,我有一个父pom a和子pom B、C和D。在B、C和D中,我有相同类型的依赖项 即 母体聚甲醛 <artifactID>blah</artifactID> <modules> <module>B</module> <module>C</module> <module>D</module> </modules&g

我有一个父pom a和子pom B、C和D。在B、C和D中,我有相同类型的依赖项

即 母体聚甲醛

    <artifactID>blah</artifactID>
    <modules>
        <module>B</module>
        <module>C</module>
        <module>D</module>
    </modules>
废话
B
C
D
儿童Pom

    <dependencies>
          <dependency>
              .
              .
              <scope>test</scope>
              <type>test-jar</type>
          </dependency>
    </dependencies>

.
.
测试
试验罐
到目前为止,我已经尝试过编辑插件surefire,但在尝试排除子POM的测试范围时,这并没有起作用

我的问题是,是否有一种方法可以将概要文件添加到父pom中,以排除所有子pom的类型测试jar的所有依赖项。
谢谢

因为您正在尝试更新
test
范围中的路径,所以您可以钩住
maven-surfere插件
,它实际上负责构建测试类路径并排除不需要的依赖项或添加新的依赖项。因此,如果您希望每个模块应用此限制,您可以在子POM中添加以下条目,例如对于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>

...
B
...
org.apache.maven.plugins
maven surefire插件
2.17
${不需要的依赖项groupId}:${不需要的依赖项artifactId}
...
或者,如果希望所有子模块都继承此限制,请在父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>

...
A.
B
C
D
...
自定义测试目标
org.apache.maven.plugins
maven surefire插件
2.17
${不需要的依赖项groupId}:${不需要的依赖项artifactId}
...

您是否在寻找一种不指定每个模块的方法?是否可以在使用测试jar的子pom中放置一个配置文件,而父pom不使用此配置文件?请看这个--->您好,因此我必须为每个模块执行此操作?有没有一种方法可以仅在父级中执行此操作或将其封装在概要文件中?您可以将此声明移动到父级pom中,然后将
声明包装在
标记中。然后,只需在子POM中调用
:org.apache.maven.plugins maven-surefire-plugin或使用基于概要文件的激活插件。我将更新答案。好的,我已经尝试过了,但是maven仍然在尝试下载依赖项,这导致了错误。我相信我的问题与我最初设想的不同。谢谢你,至少你可以把答案投上一票,如果它有助于解决一半的问题:)