java - 在基于maven配置文件的spring-boot项目中跳过maven shade插件

标签 java spring spring-boot maven java-8

当在 spring-boot 项目上激活某个 maven 配置文件时,我想跳过 maven-shade-plugin 的执行。正如本answer中提到的我已经将我的 pom.xml 制作如下

<?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>

但即使在执行 maven clean install -Pdev-local 时,我看到阴影步骤仍在执行。

有人可以建议如何在 Spring Boot 项目上启用某个配置文件时停止执行阴影吗?

最佳答案

有专门的Spring Boot Maven Plugin这还允许您重新打包您的应用程序。它的repackage目标在package阶段自动激活,因此您甚至不需要定义执行。

回到你的问题,如果你想跳过某个插件的执行,许多插件都有一个你可以设置的 skip 属性。 Spring Boot Maven 插件有一个。您可以在 XML 配置中设置它,但它还有一个用户属性。因此,您的 dev-local 配置文件可能如下所示:

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

但您甚至可以完全跳过配置文件并使用 -Dspring-boot.repackage.skip=true 调用 Maven。

Maven Shade Plugin没有记录此类属性,因此这可能是使用 Spring Boot Maven 插件而不是 Maven Shade 插件的原因。

最后,为了构建应用程序,您通常不需要 mvn clean install,但 mvn verify 就足够了。节省执行时间,从长远来看可以节省大量磁盘空间,因为它不会将构建的 Artifact 复制到本地 Maven 存储库(~/.m2/repository% userprofile%\.m2\repository).

关于java - 在基于maven配置文件的spring-boot项目中跳过maven shade插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59393863/

相关文章:

java - 记录存在+文本字段标准的问题

java - 如何删除cookies?

java - Jaxb2Marshaller 无法以线程安全的方式解码非 XmlRoot 元素

spring - TransactionTemplate 与 @Transactional(propagation = Propagation.REQUIRES_NEW)

Spring Boot : Tomcat redirects to HTTPS 8443, 无论我指定哪个 HTTPS 端口

java - 如何正确获取电影文件夹?

java - 内部类中的工厂,不可能吗?

java - 无法识别 @ContextConfiguration 的参数类

java - 重写标准 Spring MVC 异常的处理行为

java - 将 Windows 上的 JConsole 与 Linux 上的远程 Java Springboot 应用程序连接时连接失败