首页 > 解决方案 > 为什么 spring-boot-maven 插件在重新打包覆盖的战争文件时会添加战争本身?

问题描述

我有以下内容pom.xml

<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>org.example</groupId>
    <artifactId>foo-war</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.jasig.portlet</groupId>
            <artifactId>CalendarPortlet</artifactId>
            <version>2.6.2</version>
            <type>war</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.6.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>build-info</goal>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <overlays>
                        <overlay>
                            <groupId>org.jasig.portlet</groupId>
                            <artifactId>CalendarPortlet</artifactId>
                        </overlay>
                    </overlays>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

当我运行mvn package生成的重新打包的战争文件时,它包含原始战争本身WEB-INF/lib/CalendarPortlet-2.6.2.war

为什么 spring-boot 在重新打包过程中会添加战争,我该如何防止这种情况?

在我的真实项目中,我想替换已经存在的战争的一些资源并添加构建信息以供执行器显示。但是仅仅为此将工件的大小增加一倍是不可行的。

编辑:
重新包装罐子时也会出现问题。

标签: javamavenspring-bootwar

解决方案


可以通过在 spring-boot-maven 插件的配置中手动指定该工件的排除项来防止原始工件包含在重新打包的工件中:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.1.6.RELEASE</version>
    <configuration>
        <excludes>
            <exclude>
                <groupId>org.jasig.portlet</groupId>
                <artifactId>CalendarPortlet</artifactId>
            </exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>build-info</goal>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

但我仍然不知道为什么该插件在重新打包的插件中包含原始工件。


推荐阅读