Spring REST Docs maven持续构建?

时间:2018-11-27 08:58:29

标签: spring-boot-maven-plugin spring-restdocs

我正在阅读本教程https://www.youtube.com/watch?v=k5ncCJBarRI&t=1443s

在大约1:07:30左右,作者后来提到“ Gradle具有连续构建”,它能够检测到测试中的变化并自动重新生成asciidoc。我想知道是否有人知道如何在Maven中进行设置?

我已经查看了spring和asciidoctor插件中的文档,但找不到与此相关的任何内容。

通过将<goal>process-asciidoc更改为auto-refresh,当index.adoc发生变化时,我能够使maven重新呈现html。但是,这不会监视测试中的更改。

问题

有没有办法告诉Maven观察我们的测试文件并在进行更改时重新编译?

POM.XML

<plugin>
    <groupId>org.asciidoctor</groupId>
    <artifactId>asciidoctor-maven-plugin</artifactId>
    <version>1.5.7.1</version>
    <executions>
        <execution>
            <id>generate-docs</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>auto-refresh</goal>
            </goals>

            <configuration>
                <sourceDocumentName>index.adoc</sourceDocumentName>
            <backend>html</backend>
            <attributes>
                <snippets>${project.build.directory}/generated-snippets</snippets>
            </attributes>
            </configuration>

        </execution>
    </executions>
</plugin>

谢谢。

2 个答案:

答案 0 :(得分:0)

Maven没有等效于Gradle的连续构建。如果要检测测试中的更改并触发测试的重新编译以及执行(直接或间接)依赖于已编译测试类的所有任务,则必须使用Gradle。

答案 1 :(得分:0)

这不是一个连续的构建解决方案,但它的工作原理类似。但是,该过程确实需要一些时间,因为它每次发生更改时都会对项目进行重新打包...对于某些用例来说可能不是理想的选择...

我找到了一个监视文件的插件。 https://github.com/fizzed/maven-plugins 将监视目录更改为测试文件所在的目录。将目标从compile更改为package

在检测到更改时,Watcher将执行mvnw: package。然后,asciidoctor maven插件将重新打包项目。

将此添加到您的插件

<plugin>
            <groupId>com.fizzed</groupId>
            <artifactId>fizzed-watcher-maven-plugin</artifactId>
            <version>1.0.6</version>
            <configuration>
                <touchFile>target/classes/watcher.txt</touchFile>
                <watches>
                    <watch>
                        <directory><directory>src/test/[your test package]</directory></directory>
                    </watch>
                </watches>
                <goals>
                    <goal>package</goal>
                    <!-- <goal>compile</goal> -->
                </goals>
                <profiles>
                    <profile>optional-profile-to-activate</profile>
                </profiles>
            </configuration>
        </plugin>