swagger-api / swagger-api/swagger-codegen

I am unable to configure the plugin to overwrite the generated pom.xml file

Open
#8,525 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

In my workflow, I want to allow a parameter to be passed in to specify the artifact version of the generated SDK.

In my project pom.xml, I have a property:
<sdk.artifact.version>LOCAL_SNAPSHOT</sdk.artifact.version>

and I then use that property in the configuration of my swagger-codegen-maven-plugin:
${sdk.artifact.version}

I can then pass in something for version at build time to generate the SDK with a different version:
mvn install -Dsdk.artifact.version=2.5.1

This works as long as the generated pom.xml does not already exist. However, if it does exist, and I attempt to generate it with a different specified version, the pom.xml is never overwritten, and I can never update the version unless I manually delete the pom.xml file.

I am using swagger-codegen-maven-plugin version 2.3.1.

I have tried 2 solutions to allow my pom.xml to be overwritten, neither of them worked, and the overwrite is still being skipped for my pom.xml.

Solution 1: I added <skipOverwrite>false</skipOverwrite> to the configuration section of my plugin xml in my project's pom.xml file.

        <plugin>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.3.1</version>
            <executions>
                <execution>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <output>${project.parent.basedir}/java-client-sdk</output>
                        <inputSpec>${project.parent.basedir}/generated/swagger-codegen-spec/swagger.json</inputSpec>
                        <language>java</language>
                        <groupId>com.redacted</groupId>
                        <artifactId>java-client-sdk</artifactId>
                        <artifactVersion>${sdk.artifact.version}</artifactVersion>
                        <invokerPackage>redacted</invokerPackage>
                        <apiPackage>redacted</apiPackage>
                        <modelPackage>redacted</modelPackage>
                        <generateApiTests>false</generateApiTests>
                        <skipOverwrite>false</skipOverwrite>
                        <configOptions>
                            <dateLibrary>java8</dateLibrary>
                        </configOptions>
                        <library>resttemplate</library>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Solution 2: I added an exclusion for pom.xml to the .swagger-codegen-ignore file

#Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

!pom.xml

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the swagger-codegen-maven-plugin generate entry point and inspect how an existing pom.xml is handled alongside .swagger-codegen-ignore. Reproduce generation with different sdk.artifact.version values and an existing generated pom.xml. Done means the configured version can update the generated pom.xml without manual deletion, while ignore behavior remains consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.