0

I have a parent pom A with children pom B, C and D. In the B, C and D, I have dependencies with the same type.

ie Parent Pom

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

child Pom

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

So far I have tried editing the plugin-surefire and that did not work when trying to exclude the test scope for the child poms.

My question is if there is a way to add a profile to the parent pom to exclude all dependencies with the type test-jar for all child poms. Thanks

Brandon Fung
  • 27
  • 1
  • 7

1 Answers1

0

Since you are trying to update paths in test scope, you can hook the maven-surfire-plugin which is actually responsible of building test classpath and exclude undesired dependencies or add new ones. So, if you want this restriction to be applied per module you can add below entry to child poms, e.g. for 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>

Or if you want this restriction to be inherited by all child modules, do define in parent pom as profile based plugin:

<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>
tmarwen
  • 15,750
  • 5
  • 43
  • 62
  • Hi So I would have to do this for each module? Is there a way to do this just in the parent or encapsulate it in a profile? – Brandon Fung Apr 22 '14 at 13:24
  • You can move this declaration into parent pom then wrap the `` declaration inside `` tag. Then simply inside child poms call that ``: org.apache.maven.plugins maven-surefire-plugin Or use profile based activation plugin. I will update the answer. – tmarwen Apr 22 '14 at 14:24
  • Alright, So I have tried that but maven is still trying to download the dependency, which is causing the error. I believe my problem is different then I first assumed. Thanks – Brandon Fung Apr 22 '14 at 15:05
  • At least you can upvote the answer if it helped figuring out half of the way :) – tmarwen Apr 22 '14 at 15:49