OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java][Spring] Source folder should be added to Maven pom.xml if it is not src/main/java
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Spring generator templates that render pom.xml and inspect how the sourceFolder property is handled. Reproduce the issue with the provided generation command, then run mvn clean install in the generated project. Done means a non-default sourceFolder is registered as a Maven source directory while the default path remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100