0

I want to skip the execution of maven-shade-plugin when a certain maven profile is activated on a spring-boot project. As mentioned in this answer I have made my pom.xml like below

<?xml version="1.0" encoding="UTF-8"?>
<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>com.van.saasinfra</groupId>
    <artifactId>saas-controller</artifactId>
    <version>0.001-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>saas-controller</name>
    <description>SaaS Controller</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.21.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>


    <dependencies>
    ...
    </dependencies>

    <profiles>
        <profile>
            <id>dev-local</id>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${mvn.shade.plugin.version}</version>
                <executions>
                    <execution>
                        <id>saas-controller-shade</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <target>
                                <mkdir dir="${project.build.directory}/generated-sources"/>
                                <exec executable="protoc">
                                    <arg value="--java_out=${project.build.directory}/generated-sources"/>
                                    <arg value="--proto_path=${project.basedir}/src/main/proto"/>
                                    <arg value="${project.basedir}/src/main/proto/com/van/saasinfra/saascontroller/saas-controller.proto"/>
                                    <arg value="${project.basedir}/src/main/proto/com/van/saasinfra/saascontroller/billing-controller.proto"/>
                                    <arg value="${project.basedir}/src/main/proto/com/van/saasinfra/saascontroller/node-topology.proto"/>
                                    <arg value="${project.basedir}/src/main/proto/com/van/saasinfra/saascontroller/availability.proto"/>
                                    <arg value="${project.basedir}/src/main/proto/com/van/saasinfra/saascontroller/dynamodb-config.proto"/>
                                    <arg value="${project.basedir}/src/main/proto/com/van/saasinfra/saascontroller/tenant-migration.proto"/>
                                </exec>
                            </target>
                            <sourceRoot>${project.build.directory}/generated-sources/</sourceRoot>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

But even when doing maven clean install -Pdev-local I am seeing shade step is still getting executed.

Can some suggest how to stop the execution of shade when a certain profile is enabled on a spring boot project?

tuk
  • 5,941
  • 14
  • 79
  • 162

1 Answers1

1

There is a dedicated Spring Boot Maven Plugin that also allows you to repackage your application. Its repackage goal automatically activates during the package phase, so you don't even need to define an execution.

Back to your question, if you want to skip execution of a certain plugin, many plugins have a skip property that you can set. The Spring Boot Maven Plugin has one. You can set it in the XML configuration, but there's also a user property for it. As a result, your dev-local profile could look like this:

<profile>
    <id>dev-local</id>
    <properties>
        <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
    </properties>
</profile>

But you could even skip the profile completely and invoke Maven with -Dspring-boot.repackage.skip=true.

The Maven Shade Plugin has no such property documented, so that could be a reason for using the Spring Boot Maven Plugin over the Maven Shade Plugin.

Finally, for building applications, you typically don't need mvn clean install, but mvn verify would be enough. Saves you a few seconds in execution and saves a lot of disk space in the long run since it doesn't copy built artifacts to your local Maven repo (~/.m2/repository or %userprofile%\.m2\repository).

mthmulders
  • 9,483
  • 4
  • 37
  • 54
  • 1
    I claim that no commandline argument should effect the resulting artifact. Hence, to me it makes sense that the maven-shade-plugin has no skip parameter. – Robert Scholte Dec 20 '19 at 08:44
  • Would that include activating or deactivating profiles? – mthmulders Dec 20 '19 at 08:51
  • 2
    Yes. And this is where it gets tricky. For that reason most Maven Developers avoid profiles, they've become too powerful. Valid usage of profiles: integration-tests (might take too long), codecoverage (activate it on the buildserver). Invalid (worst) usage: dev/test/prod. These imply embedded environment configuration. – Robert Scholte Dec 20 '19 at 11:45