[BUG][Java][Spring] Source folder should be added to Maven pom.xml if it is not src/main/java
Created by: jmaister
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I am generating a project setting a different source folder than the default for a Maven project. The idea is to have the implementations in src/main/java and the generated sources in src/gen/java.
openapi-generator-cli generate -g spring -i ../openapi/tags.yml -o ../src/service-tags-java/ --enable-post-process-file --additional-properties=.......,sourceFolder=src/gen/java,......
The problem is that the gen
folder is not added as a source folder in the pom.xml file. Therefore, the Maven build fails:
openapi-generator version
"@openapitools/openapi-generator-cli": "2.4.18"
OpenAPI declaration file content or url
No specific OpenAPI file, the problem would happen with any file.
Generation Details
- Generate the project
openapi-generator-cli generate -g spring -i openapi/tags.yml -o service-tags-java/ --enable-post-process-file --additional-properties=apiPackage=com.example.tags.api,artifactDescription=tags_api,groupId=com.example,artifactId=service-tags,artifactVersion=1.0.0,basePackage=com.example.tags,dateLibrary=java8,delegatePattern=true,java8=true,library=spring-boot,sourceFolder=src/gen/java,invokerPackage=com.example.tags,modelPackage=com.example.tags.model,configPackage=com.example.tags.config
Steps to reproduce
-
Maven build after generating the code
cd service-tags-java/ mvn clean install
Related issues/PRs
Suggest a fix
The fix consists in adding an additional source folder to the project. There is an example in here: https://www.baeldung.com/maven-project-multiple-src-directories
In the pom.xml file, add the next plugin if the sourceFolder
parameter is different from src/main/java
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/another-src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>