Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #10964
Closed
Open
Issue created Nov 25, 2021 by Administrator@rootContributor4 of 6 checklist items completed4/6 checklist items

[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
  1. 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
  1. 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>
Assignee
Assign to
Time tracking