Ajeetkumar
Ajeetkumar

Reputation: 1329

format openapi/swagger generated java source using maven plugin

I've openapi plugin to autogenerate some java source code using mustache files as template.

I wish to format this code using google java style. I followed example at this link: https://shankulk.com/format-your-java-code-with-google-java-format-5bf4de8756f5

This works but it formats the entire source code at src/main/java and src/main/test

I wish to format only generated code which is in target/ I tried using path as highlighted but it still formats the entire source code including auto generated code in target/

is there other standard maven plugin that can be used for this purpose or how can i set this up?

enter image description here

Upvotes: 0

Views: 550

Answers (1)

TSF
TSF

Reputation: 36

For your problem directly i would just change the source directory to be directory you want target/generated-srcs/open-api/src/main/java and remove the testDirectory. I'd also remove the check since you are formatting generated code and it would be dumb to fail on that.

Here is my quick hacky solution.

<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>

Upvotes: 0

Related Questions