Skip to content
Advertisement

How to skip the maven antrun copy/shade:shade goal dynamically?

I am using maven for configuration of an application consisting of multiple small services. Most of the services developed in java share the same maven configuration, as in the same build lifecycle, some shared resources (like spring AMQP).

So I have organized the shared resources in a SuperPom.

While the shade plugin doesn’t really seem to disturb the install process, the antrun plugin of course won’t find any of the files it should copy, due to there not being created any jar files by the shade plugin.

As I’d like the configuration of the shade/antrun plugin to be abstracted in the SuperPom, I need to skip the shade/copy goal.

I have tried mvn clean install -Dmaven.shade.skip=true, mvn clean install -Dmaven.copy.skip=true, mvn clean install -Dmaven.shade.shade.skip=true

Here is a small sample for you to play with:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Test</groupId>
    <artifactId>SuperTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
        <log4j.version>1.2.17</log4j.version>
        <destination>pleasedeleteme</destination>
        <mainpackage>com.uk.cc.it.info.gov.test.xxx</mainpackage>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>${mainpackage}.Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>${groupId}</groupId>
                                    <artifactId>${artifactId}</artifactId>
                                    <version>${version}</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${destination}</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
    </dependencies>

</project>

Advertisement

Answer

The maven-shade-plugin doesn’t have a parameter to skip. Often the shade-plugin isn’t there just for fun, so you might wonder if you really want to skip this. If you think it is still valid, you have to create a profile with activation like this:

<activation>
  <property>
    <name>skipShade</name>
    <value>!true</value>
  </property>
</activation>

This way it is activated by default, unless you add -DskipShade or -DskipShade=true.

6 People found this is helpful
Advertisement