1

I have a maven project for which I'm running two separate builds.

In one build I want to save the build time by disabling the jar creation of maven modules in it.(There are 45 maven modules). There is a Maven-Jar-Plugin that is being used to create the jars.

I want to conditionally disable the jar creation at the command line, that is, looking for something similar to -Dskiptests used to skip the unit tests though there is a surefire plugin by default.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
Priyanka.Patil
  • 1,177
  • 2
  • 15
  • 34

1 Answers1

3

The maven-jar-plugin does not provide any skip option.

However, several ways are possible to achieve your requirement.

You may just skip the phase which brings by default (via default mappings) the jar creation, that is, the package phase, and as such simply invoke

mvn clean test

The additional phases would not make sense if you do not create a jar file anyway: package, install, deploy would not have anything to process. Moreover, the additional integration phases may also be impacted depending on your strategy for integration tests, if any.

Alternatively, you can configure your pom as following:

<properties>
    <jar.creation>package</jar.creation>
</properties>

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>default-jar</id>
            <phase>${jar.creation}</phase>
          </execution>
        </executions>
      </plugin>
    </plugins>
</build>

As such, the default behavior would still provide a jar creation, while executing maven as following:

mvn clean install -Djar.creation=false

Would instead skip the creation of the jar.

What we are actually doing:

  • We are re-defining the default execution of the maven-jar-plugin
  • We are overriding its execution id, as such getting more control over it
  • We are placing its execution phase binding to a configurable (via property) phase
  • Default phase (property value) keeps on being package
  • At command line time you can still change it to any value different than a standard maven phase. That is, -Djar.creation=none would also work.
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • @Priyanka.Patil was the answer helpful? you didn't share any further feedback nor [accept](http://meta.stackexchange.com/q/5234/314893). Just checking. – A_Di-Matteo Jun 23 '16 at 13:40