Spring boot Maven jar 插件在复制资源之前运行

问题描述

我正在运行 spring boot 应用程序并使用 asciidoctor-maven-plugin for API 创建 ascii 文档。 我想将生成的 html 文件包含在可执行的 spring boot jar 文件中,以便我可以使用 url http://localhost:8080/static/docs/myapi.html

访问它

问题是 maven 在创建这个 ascii 文档之前创建了 jar 文件生成的 jar 文件不包含此文件。但之后它会被复制到 \target\classes\static\docs 文件夹中。我知道 maven pom 文件的执行顺序有问题。我在这里复制我的pom。任何人都可以修复订单吗?

我想要以下顺序。

  1. 运行集成测试
  2. 生成 ascii 文档
  3. 生成的文档复制到 target\classes\static\docs
  4. 构建jar文件
  5. 制作可执行的jar

问题在于它在生成 ascii 文档之前生成了 jar 文件

这是我的 pom 构建部分。

<build>
    <plugins>
        <plugin>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <version>2.1.0</version>
            <executions>
                <execution>
                    <id>generate-docs</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>process-asciidoc</goal>
                    </goals>
                    <configuration>
                        <backend>html</backend>
                        <doctype>book</doctype>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.restdocs</groupId>
                    <artifactId>spring-restdocs-asciidoctor</artifactId>
                    <version>${spring-restdocs.version}</version>
                </dependency>
            </dependencies>
        </plugin>

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                            ${project.build.outputDirectory}/static/docs
                        </outputDirectory>
                        <resources>
                            <resource>
                                <directory>
                                    ${project.build.directory}/generated-docs
                                </directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                        <goal>build-info</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
        </plugin>
    </plugins>
</build>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)