14

I have a Maven build with three modules.

  • Module A exports a jar.
  • Module B depends on A and exports a jar.
  • Module C is a set of regression tests that depend on A and B.

The reason the regression tests aren't just part of module B is that they should be able to run against multiple versions of A and B to ensure backwards compatibility. I want to be able to run deploy from the top level build to create A.jar and B.jar, but not C.jar. Is this possible?

Craig P. Motlin
  • 26,452
  • 17
  • 99
  • 126
  • Related: [What is the best way to avoid maven-jar?](http://stackoverflow.com/questions/2188746/what-is-the-best-way-to-avoid-maven-jar) – sleske May 18 '15 at 13:07

4 Answers4

9
<properties>
     <maven.deploy.skip>true</maven.deploy.skip>
</properties>

If you don't need to create a JAR at all, you might want to add two more properties:

<jar.skipIfEmpty>true</jar.skipIfEmpty>
<maven.install.skip>true</maven.install.skip>

Note that you still need maven.deploy.skip, otherwise the build will fail during deployment.

sleske
  • 81,358
  • 34
  • 189
  • 227
Craig P. Motlin
  • 26,452
  • 17
  • 99
  • 126
  • I took the liberty of adding how to suppress the creation of the JAR, in case it is not needed. – sleske May 18 '15 at 13:02
6

The maven deploy plugin includes a skip options that prevents artifact deployment.

<plugin>
  <artifactId>maven-deploy-plugin</artifactId>
  <configuration>
      <skip>true</skip>
  </configuration>
</plugin>

You can try adding that to project C.

sal
  • 23,373
  • 15
  • 66
  • 85
3

Use below for module C:

<packaging>pom</packaging>
Taylor Leese
  • 51,004
  • 28
  • 112
  • 141
  • I tried that. Then I run mvn test from the top level, and C's tests don't run. – Craig P. Motlin Feb 05 '10 at 23:25
  • You may need to reorganize the heirarchy of your POM's. For example, you may need a super pom at the top and then C as a sub-module and then A and B as submodules under C. – Taylor Leese Feb 05 '10 at 23:29
  • If you choose packaging type of pom, you'll need to manually rebind all the usual plugins as per Pascal's answer below. You still want jar packaging for C, you just need to disable deployment for that module. sal has the right answer here. – joelittlejohn Feb 23 '11 at 10:48
3

Use a packaging of type pom for C and rebind all required plugins:

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <executions>
          <execution>
            <id>test-compile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>process-test-resources</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <executions>
          <execution>
            <id>test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • While that probably works, it is rather verbose. Craig P. Motlin's answer provides a nicer solution. – sleske May 18 '15 at 13:03