Luciano
Luciano

Reputation: 2999

Switching "maven-assembly-plugin" on/off

Our current DevOps environment runs mvn package and auto-deploys the jar artifact in a private Maven repository and all target folder is cached for later use. But the project has also a maven-assembly-plugin set up what packages a second jar file (a fat jar suffixed as -jar-with-dependencies).

We don't want the "fat jar" to be generated by maven-assembly-plugin and so stored in that cache along with other files in that case.

Is there a way to switch maven-assembly-plugin on and off by command line (or any other property or environment variable) to run it only when explicitly required?

Upvotes: 1

Views: 1259

Answers (2)

J Fabian Meier
J Fabian Meier

Reputation: 35825

You can set the property assembly.skipAssembly to true.

Either on command line ( with -Dassembly.skipAssembly=true) or in the POM itself.

Upvotes: 2

Mureinik
Mureinik

Reputation: 311448

The easiest approach (IMHO), would be to define the plugin in its own profile. Inside your pom.xml, you add a profiles section, and in that a profile that would include the plugin:

<profiles>
  <profile>
    <id>assemble</id>
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-assembly-plugin</artifactId>
          <!-- All the configuration you have for the plugin -->
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>

Then, by default, this plugin will not be called. When you want to call it, you can explicitly enable this profile with the -P flag:

mvn package -Passemble

Upvotes: 2

Related Questions