使用maven插件格式化openapi/swagger生成的java源

问题描述 投票:0回答:1

我有

openapi
插件,可以使用
mustache
文件作为模板自动生成一些 java 源代码。

我希望使用 google java 风格格式化此代码。我按照此链接中的示例进行操作: https://shankulk.com/format-your-java-code-with-google-java-format-5bf4de8756f5

这可行,但它会在

src/main/java
src/main/test

处格式化整个源代码

我希望仅格式化

target/
中生成的代码 我尝试使用突出显示的路径,但它仍然格式化整个源代码,包括
target/

中自动生成的代码

是否有其他标准 Maven 插件可用于此目的,或者我该如何设置?

maven google-java-format
1个回答
0
投票

直接针对您的问题,我只需将源目录更改为您想要的目录

target/generated-srcs/open-api/src/main/java
并删除
testDirectory
。我还会删除该检查,因为您正在格式化生成的代码,如果失败那就太愚蠢了。

这是我的快速解决方案。

<plugin>
    <groupId>com.coveo</groupId>
    <artifactId>fmt-maven-plugin</artifactId>
    <version>2.9</version>
    <configuration>
        <sourceDirectory>target/generated-srcs/open-api/src/main/java</sourceDirectory>
        <verbose>false</verbose>
        <filesNamePattern>.*\.java</filesNamePattern>
        <skip>false</skip>
        <skipSortingImports>false</skipSortingImports>
        <style>google</style>
    </configuration>
</plugin>
© www.soinside.com 2019 - 2024. All rights reserved.