2014-04-21 77 views
0

我有一个包含子pom B,C和D的父pom A.在B,C和D中,我拥有相同类型的依赖关系。从父pom中删除子pom的maven依赖关系

即 父POM

<artifactID>blah</artifactID> 
    <modules> 
     <module>B</module> 
     <module>C</module> 
     <module>D</module> 
    </modules> 

孩子双龙

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

到目前为止,我已经尝试编辑插件,万无一失,并试图排除孩子劲歌测试范围时,没有工作。

我的问题是,如果有一种方法可以添加配置文件到父pom中,以排除所有子poms的类型test-jar的所有依赖关系。 感谢

+0

您是否正在寻找一种方式没有指定每一个呢? –

+0

是否可以将配置文件放置在使用测试jar的子pom中,并且父pom不使用此配置文件? –

+0

看看这个---> http://stackoverflow.com/questions/12053316/exclude-maven-dependency-for-tests – ivoruJavaBoy

回答

0

既然你想在test范围更新路径,可以勾maven-surfire-plugin这实际上是负责构建测试类路径和排除不必要的依赖或添加新的。因此,如果您希望将此限制应用于每个模块,您可以在以下条目中添加儿童poms,例如,为

<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> 
+0

嗨所以我必须为每个模块做到这一点?有没有办法做到这一点,只是在父母或封装在配置文件? –

+0

您可以将此声明移入父pom,然后在''标记内包装''声明。然后,只需里面的孩子劲歌调用'' org.apache.maven.plugins Maven的万无一失,插件 或者使用基于简档的激活插件。我会更新答案。 – tmarwen

+0

好吧,所以我试过,但maven仍然试图下载依赖项,这是导致错误。我相信我的问题与我第一次假设不同。谢谢 –