Unpack WAR 不是解包

Unpack WAR Is Not Unpacking

我正在尝试实现与 here 发布的问题相同的 objective,即 assemble 将 war 依赖项放入可部署的 zip 中,同时 war 和它的一些解压 *.yml 文件在最终的 zip 中。我已将 war 文件正确 assembled 放入 zip,但我无法使用 maven-dependency-plugin 将 *.yml 文件从 war 中解压缩以重新打包打包.

为清楚起见,这是我所拥有的:

我的插件声明如下所示:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>myapp</groupId>
                                <artifactId>myapp-war</artifactId>
                                <type>war</type>
                                <outputDirectory>${project.build.directory}/unpack</outputDirectory>
                                <includes>**/*.yml</includes>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我还尝试了一种变体,我在 <configuration> 下方声明了 <outputDirectory><includes>,这是 unpack mojo docs 允许的。

在任何一种情况下,我都会得到一个空的 myapp-deploy/target/unpack 文件夹,以及 Maven 输出中的 [INFO] 和 [DEBUG] 消息:

[INFO] Configured Artifact: myapp:myapp-war:?:war
[INFO] Unpacking /build/myapp-war/target/myapp-war-0.0.1-SNAPSHOT.war to /build/myapp-deploy/target/unpack with includes "**/*.yml" and excludes ""
[DEBUG] Found unArchiver by type: org.codehaus.plexus.archiver.zip.ZipUnArchiver$__sisu2@692a65b1
[DEBUG] Expanding: /build/myapp-war/target/myapp-war-0.0.1-SNAPSHOT.war into /build/myapp-deploy/target/unpack
[DEBUG] expand complete

看来 maven 已经理解了我的指令,但似乎并没有像它声称的那样解包。知道我做错了什么吗?

创建 *.war 依赖项显然有问题。它首先使用 maven-war-plugin:war 创建,然后使用 spring-boot-maven-plugin:repackage 重新打包。从命令行解压缩 war 成功,但会生成 warning:

$ unzip myapp-war-0.0.1-SNAPSHOT.war
Archive:  myapp-war-0.0.1-SNAPSHOT.war
warning [myapp-war-0.0.1-SNAPSHOT.war]:  7318 extra bytes at beginning or within zipfile

如果我配置 spring-boot-maven-plugin:repackage 以禁用 executable *nix 启动脚本到 war 的前置,maven-dependency-plugin:unpack 将按预期工作:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>false</executable>
    </configuration>
</plugin>