You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Debraj Manna <su...@gmail.com> on 2019/12/20 05:04:11 UTC

Skipping maven shade plugin in a spring-boot project based on maven profile

I am cross-posting from stackoverflow
<https://stackoverflow.com/questions/59393863/skipping-maven-shade-plugin-in-a-spring-boot-project-based-on-maven-profile>
as I did not get any reply there.

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
<https://stackoverflow.com/a/13383092/785523> 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?

Re: Skipping maven shade plugin in a spring-boot project based on maven profile

Posted by Debraj Manna <su...@gmail.com>.
Thanks Maarten.

On Fri, Dec 20, 2019 at 12:07 PM Maarten Mulders <ma...@mulders.it> wrote:

> Also cross-posting from StackOverflow [1], where I just answered your
> question:
>
>
> There is a dedicated Spring Boot Maven Plugin [2] 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 [3] 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).
>
>
> Hope this helps,
>
>
> Maarten
>
> References:
> [1] https://stackoverflow.com/a/59420813/1523342
> [2]
> https://docs.spring.io/spring-boot/docs/current/maven-plugin/index.html
> [3] https://maven.apache.org/plugins/maven-shade-plugin/index.html
>
> On December 20, 2019 at 06:04, Debraj Manna wrote:
>
> > I am cross-posting from stackoverflow
> > <
> https://stackoverflow.com/questions/59393863/skipping-maven-shade-plugin-in-a-spring-boot-project-based-on-maven-profile
> >
> > as I did not get any reply there.
> >
> > 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
> > <https://stackoverflow.com/a/13383092/785523> 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?
>

Re: Skipping maven shade plugin in a spring-boot project based on maven profile

Posted by Maarten Mulders <ma...@mulders.it>.
Also cross-posting from StackOverflow [1], where I just answered your 
question:


There is a dedicated Spring Boot Maven Plugin [2] 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 [3] 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).


Hope this helps,


Maarten

References:
[1] https://stackoverflow.com/a/59420813/1523342
[2] 
https://docs.spring.io/spring-boot/docs/current/maven-plugin/index.html
[3] https://maven.apache.org/plugins/maven-shade-plugin/index.html

On December 20, 2019 at 06:04, Debraj Manna wrote:

> I am cross-posting from stackoverflow
> <https://stackoverflow.com/questions/59393863/skipping-maven-shade-plugin-in-a-spring-boot-project-based-on-maven-profile>
> as I did not get any reply there.
> 
> 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
> <https://stackoverflow.com/a/13383092/785523> 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?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org