I found this answer. You just need to change pom.xml like below.

pom.xml.

<properties>
           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
           <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
           <java.version>1.8</java.version>
           <version.swagger.codegen>2.2.1</version.swagger.codegen>
           <yaml.file>${project.basedir}/src/main/resources/Api.yaml</yaml.file>
           <generated-sources-path>${project.build.directory}/generated-sources</generated-sources-path>
           <generated-sources-java-path>main/java</generated-sources-java-path>
       </properties>

<build>
           <plugins>
               <plugin>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-maven-plugin</artifactId>
               </plugin>
               <plugin>
                   <groupId>io.swagger</groupId>
                   <artifactId>swagger-codegen-maven-plugin</artifactId>
                   <version>${version.swagger.codegen}</version>
                   <configuration>
                       <inputSpec>${yaml.file}</inputSpec>
                       <configOptions>
                           <sourceFolder>${generated-sources-java-path}</sourceFolder>
                       </configOptions>
                       <output>${generated-sources-path}</output>
                   </configuration>
                   <executions>
                       <execution>
                           <id>generate-swagger-spring</id>
                           <phase>generate-sources</phase>
                           <goals>
                               <goal>generate</goal>
                           </goals>
                           <configuration>
                               <language>spring</language>
                               <modelPackage>${project.groupId}.swagger.model</modelPackage>
                               <apiPackage>${project.groupId}.swagger.api</apiPackage>
                               <invokerPackage>${project.groupId}.swagger.invoker</invokerPackage>
                           </configuration>
                       </execution>
                   </executions>
               </plugin>        
               <plugin>
                   <groupId>org.codehaus.mojo</groupId>
                   <artifactId>build-helper-maven-plugin</artifactId>
                   <executions>
                       <execution>
                           <id>add-generated-source</id>
                           <phase>initialize</phase>
                           <goals>
                               <goal>add-source</goal>
                           </goals>
                           <configuration>
                               <sources>
                                   <source>${generated-sources-path}/${generated-sources-java-path}</source>
                               </sources>
                           </configuration>
                       </execution>
                   </executions>
               </plugin>                
           </plugins>   

       <pluginManagement>
           <plugins>
               <plugin>
                   <groupId>org.eclipse.m2e</groupId>
                   <artifactId>lifecycle-mapping</artifactId>
                   <version>1.0.0</version>
                   <configuration>
                       <lifecycleMappingMetadata>
                           <pluginExecutions>
                               <pluginExecution>
                                   <pluginExecutionFilter>
                                       <groupId>io.swagger</groupId>
                                       <artifactId>swagger-codegen-maven-plugin</artifactId>
                                       <versionRange>[${version.swagger.codegen},)</versionRange>
                                       <goals>
                                           <goal>generate</goal>
                                       </goals>
                                   </pluginExecutionFilter>
                                   <action>
                                       <execute />
                                   </action>
                               </pluginExecution>
                           </pluginExecutions>
                       </lifecycleMappingMetadata>
                   </configuration>
               </plugin>
           </plugins>
       </pluginManagement>          
       </build>
Answer from rajesh reddy SR on Stack Overflow
🌐
Maven Repository
mvnrepository.com › artifact › io.swagger › swagger-codegen-maven-plugin
Maven Repository: io.swagger » swagger-codegen-maven-plugin
March 12, 2026 - maven plugin to build modules from swagger codegen · LicenseApache 2.0 · CategoriesMaven Plugins · Tagsplugingeneratorbuildbuild-systemopenapicodemavenswaggerapi · Ranking · #530554in MvnRepository · #145in Maven Plugins · HomePage https://github.com/swagger-api/swagger-codegen 🔍 Inspect URL ·
About
Welcome to MvnRepository! My name is Fernando Rodriguez Olivera, and I'm the founder of this website · MvnRepository is a free service that indexes the Maven repositories, providing developers with a fast and easy way to search for packages and their dependencies.
Popular
Indexed Artifacts (66.1M) · Categories (277) · Maven Plugins · Testing · Android Packages · Language Runtime · JVM Languages · Logging Frameworks · JSON Libraries · Java Specifications
Categories
Indexed Artifacts (66.1M) · Categories (277) · Maven Plugins · Testing · Android Packages · Language Runtime · JVM Languages · Logging Frameworks · JSON Libraries · Java Specifications
Maven Repository
Indexed Artifacts (66.2M) · Categories (277) · Maven Plugins · Testing · Android Packages · Language Runtime · JVM Languages · Logging Frameworks · JSON Libraries · Java Specifications
🌐
Maven Repository
mvnrepository.com › artifact › io.swagger › swagger-codegen
Maven Repository: io.swagger » swagger-codegen
March 12, 2026 - Swagger enables design, governance, and testing across the full AI-enabled API lifecycle, ensuring quality at every ... ... aar android apache api arm assets build build-system bundle client clojure cloud config cran data database eclipse example extension framework github gradle groovy io ...
🌐
Maven Repository
mvnrepository.com › artifact › io.swagger.codegen.v3
Maven Repository: io.swagger.codegen.v3
io.swagger.codegen.v3 » swagger-codegen-maven-plugin Apache · maven plugin to build modules from swagger codegen · Last Release on Feb 17, 2026 · Central · Atlassian External · Atlassian · WSO2 Releases · WSO2 Public · Hortonworks · KtorEAP · Mulesoft ·
🌐
GitHub
github.com › swagger-api › swagger-codegen › blob › master › modules › swagger-codegen-maven-plugin › README.md
swagger-codegen/modules/swagger-codegen-maven-plugin/README.md at master · swagger-api/swagger-codegen
A Maven plugin to support the swagger code generation project · Add to your build->plugins section (default phase is generate-sources phase) <plugin> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> ...
Author   swagger-api
🌐
Swagger
swagger.io › docs › open-source-tools › swagger-codegen › codegen-v3 › workflow-integration
Swagger Codegen Workflow Integration | Swagger Docs
You can use the swagger-codegen-maven-plugin for integrating with your workflow, and generating any codegen target.
🌐
GitHub
github.com › swagger-api › swagger-codegen
GitHub - swagger-api/swagger-codegen: swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition. · GitHub
It's possible to leverage Swagger Codegen directly within your preferred CI/CD workflows to streamline your auto-generation requirements. Check out the workflows integration guide to see information on our Maven, Gradle, and GitHub integration options.
Starred by 17.7K users
Forked by 6K users
Languages   Mustache 53.0% | Java 37.9% | Shell 5.1% | TypeScript 1.3% | Batchfile 0.6% | Apex 0.3%
🌐
GitHub
github.com › swagger-api › swagger-codegen › tree › master › modules › swagger-codegen-maven-plugin
swagger-codegen/modules/swagger-codegen-maven-plugin at master · swagger-api/swagger-codegen
A Maven plugin to support the swagger code generation project · Add to your build->plugins section (default phase is generate-sources phase) <plugin> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> ...
Author   swagger-api
Top answer
1 of 3
14

I found this answer. You just need to change pom.xml like below.

pom.xml.

<properties>
           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
           <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
           <java.version>1.8</java.version>
           <version.swagger.codegen>2.2.1</version.swagger.codegen>
           <yaml.file>${project.basedir}/src/main/resources/Api.yaml</yaml.file>
           <generated-sources-path>${project.build.directory}/generated-sources</generated-sources-path>
           <generated-sources-java-path>main/java</generated-sources-java-path>
       </properties>

<build>
           <plugins>
               <plugin>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-maven-plugin</artifactId>
               </plugin>
               <plugin>
                   <groupId>io.swagger</groupId>
                   <artifactId>swagger-codegen-maven-plugin</artifactId>
                   <version>${version.swagger.codegen}</version>
                   <configuration>
                       <inputSpec>${yaml.file}</inputSpec>
                       <configOptions>
                           <sourceFolder>${generated-sources-java-path}</sourceFolder>
                       </configOptions>
                       <output>${generated-sources-path}</output>
                   </configuration>
                   <executions>
                       <execution>
                           <id>generate-swagger-spring</id>
                           <phase>generate-sources</phase>
                           <goals>
                               <goal>generate</goal>
                           </goals>
                           <configuration>
                               <language>spring</language>
                               <modelPackage>${project.groupId}.swagger.model</modelPackage>
                               <apiPackage>${project.groupId}.swagger.api</apiPackage>
                               <invokerPackage>${project.groupId}.swagger.invoker</invokerPackage>
                           </configuration>
                       </execution>
                   </executions>
               </plugin>        
               <plugin>
                   <groupId>org.codehaus.mojo</groupId>
                   <artifactId>build-helper-maven-plugin</artifactId>
                   <executions>
                       <execution>
                           <id>add-generated-source</id>
                           <phase>initialize</phase>
                           <goals>
                               <goal>add-source</goal>
                           </goals>
                           <configuration>
                               <sources>
                                   <source>${generated-sources-path}/${generated-sources-java-path}</source>
                               </sources>
                           </configuration>
                       </execution>
                   </executions>
               </plugin>                
           </plugins>   

       <pluginManagement>
           <plugins>
               <plugin>
                   <groupId>org.eclipse.m2e</groupId>
                   <artifactId>lifecycle-mapping</artifactId>
                   <version>1.0.0</version>
                   <configuration>
                       <lifecycleMappingMetadata>
                           <pluginExecutions>
                               <pluginExecution>
                                   <pluginExecutionFilter>
                                       <groupId>io.swagger</groupId>
                                       <artifactId>swagger-codegen-maven-plugin</artifactId>
                                       <versionRange>[${version.swagger.codegen},)</versionRange>
                                       <goals>
                                           <goal>generate</goal>
                                       </goals>
                                   </pluginExecutionFilter>
                                   <action>
                                       <execute />
                                   </action>
                               </pluginExecution>
                           </pluginExecutions>
                       </lifecycleMappingMetadata>
                   </configuration>
               </plugin>
           </plugins>
       </pluginManagement>          
       </build>
2 of 3
5
<!-- Swagger -->
<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
        <execution>
            <id>contract-service</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${basedir}/src/main/resources/swagger/rest-data-exchange-format.yaml</inputSpec>
                <artifactId>contract-service</artifactId>
                <output>${basedir}/target/generated-sources</output>
                <language>spring</language>
                <modelPackage>ru.payhub.rest.v1.model</modelPackage>
                <apiPackage>ru.payhub.rest.v1.api</apiPackage>
                <!-- <invokerPackage>ru.payhub.rest.v1.handler</invokerPackage> -->
                <generateSupportingFiles>false</generateSupportingFiles>
                <configOptions>
                    <sourceFolder>src/main/java</sourceFolder>
                    <interfaceOnly>true</interfaceOnly>
                    <library>spring-boot</library>
                    <dateLibrary>${generator.datelibrary}</dateLibrary>
                    <configPackage>ru.payhub.config</configPackage>
                    <singleContentTypes>true</singleContentTypes>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

Official parametrs description here

Swagger syntax specification here

On this example maven plugin, used swagger data-model file (yaml) generate model classes for use it in the controllers.

Find elsewhere
🌐
Swagger
swagger.io › docs › open-source-tools › swagger-codegen › codegen-v3 › versioning
Swagger Codegen Versioning | Swagger Docs
<artifactId>swagger-codegen-maven-plugin</artifactId> 4 · <version>2.4.46</version> 5 · </dependency> dependency example: 1 · <dependency> 2 · <groupId>io.swagger.codegen.v3</groupId> 3 · <artifactId>swagger-codegen-maven-plugin</artifactId> 4 · <version>3.0.71</version> 5 ·
🌐
Maven Central
central.sonatype.com › artifact › io.swagger.codegen.v3 › swagger-codegen-maven-plugin
Maven Central: io.swagger.codegen.v3:swagger-codegen-maven-plugin
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>io.swagger.codegen.v3</groupId> <artifactId>swagger-codegen-project</artifactId> <version>3.0.78</version> <relativePath>../..</relativePath> </parent> <artifactId>swagger-codegen-maven-plugin</artifactId> <name>swagger-codegen (maven-plugin)</name> <packaging>maven-plugin</packaging> <description>maven plugin to build modules from swagger cod
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 4408668022930-Classpath-when-using-swagger-codegen-maven-plugin
Classpath when using swagger-codegen-maven-plugin – IDEs Support (IntelliJ Platform) | JetBrains
October 24, 2021 - Otherwise building the project with just maven from the command-prompt works just fine. ... <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>2.3.1</version>
🌐
Swagger
swagger.io › docs › open-source-tools › swagger-codegen › codegen-v3 › about
Swagger Codegen | Swagger Docs
It’s possible to leverage Swagger Codegen directly within your preferred CI/CD workflows to streamline your auto-generation requirements. Check out the workflows integration guide to see information on our Maven, Gradle, and GitHub integration options.
🌐
Maven Repository
mvnrepository.com › artifact › io.swagger › swagger-codegen-cli
Maven Repository: io.swagger » swagger-codegen-cli
March 12, 2026 - Swagger enables design, governance, and testing across the full AI-enabled API lifecycle, ensuring quality at every ... ... aar android apache api arm assets build build-system bundle client clojure cloud config cran data database eclipse example extension framework github gradle groovy io ...
🌐
Baeldung
baeldung.com › home › spring › spring boot › generate spring boot rest client with swagger
Generate Spring Boot Project with Swagger | Baeldung
May 11, 2024 - java -jar swagger-codegen-cli.jar generate \ -i http://petstore.swagger.io/v2/swagger.json \ --api-package com.baeldung.petstore.client.api \ --model-package com.baeldung.petstore.client.model \ --invoker-package com.baeldung.petstore.client.invoker \ --group-id com.baeldung \ --artifact-id spring-swagger-codegen-api-client \ --artifact-version 0.0.1-SNAPSHOT \ -l java \ --library resttemplate \ -o spring-swagger-codegen-api-client ... Names of packages for generated classes – provided using –api-package, –model-package, –invoker-package · Generated Maven project properties –group-id, –artifact-id, –artifact-version
🌐
Maven Repository
mvnrepository.com › artifact › io.swagger.codegen.v3 › swagger-codegen-maven-plugin
Maven Repository: io.swagger.codegen.v3 » swagger-codegen-maven-plugin
February 17, 2026 - Home » io.swagger.codegen.v3 » swagger-codegen-maven-plugin · maven plugin to build modules from swagger codegen · LicenseApache 2.0 · CategoriesMaven Plugins · Tagsplugingeneratorbuildbuild-systemopenapicodemavenswaggerapi · Ranking · #540423in MvnRepository ·
🌐
Maven Central
central.sonatype.com › artifact › io.swagger › swagger-codegen
io.swagger:swagger-codegen - Maven Central - Sonatype
<dependency> <groupId>io.swagger</groupId> <artifactId>swagger-codegen</artifactId> <version>2.4.50</version> </dependency> ... <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-project</artifactId> <version>2.4.50</version> <relativePath>../..</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>swagger-codegen</artifactId> <packaging>jar</packaging> <name>sw
🌐
Melissapalmer
melissapalmer.github.io › documentation › 2018 › 07 › 27 › swagger-codegen-2-java-with-maven.html
Swagger Codegen 2 Java Classes with Maven
Swagger Codegen can be used to ... generate the basis for calling other APIs in a polygot environment. ... A maven build plugin which allows the codegen project to be triggered for generating clients, etc....
🌐
Javadoc.io
javadoc.io › doc › io.swagger › swagger-codegen-maven-plugin › latest › index.html
swagger-codegen-maven-plugin 3.0.0-rc1 javadoc (io.swagger)
Latest version of io.swagger:swagger-codegen-maven-plugin · https://javadoc.io/doc/io.swagger/swagger-codegen-maven-plugin · Current version 3.0.0-rc1 · https://javadoc.io/doc/io.swagger/swagger-codegen-maven-plugin/3.0.0-rc1 · package-list path (used for javadoc generation -link option) ...
🌐
OpenAPI Generator
openapi-generator.tech › migrating from swagger codegen
Migrating from Swagger Codegen | OpenAPI Generator
Old: swaggerapi/swagger-codegen-cli · New: openapitools/openapi-generator-cli · OpenAPI Generator as web service · Image to run OpenAPI Generator as a web service (see OpenAPI Generator Online Docker Image) Old: swaggerapi/swagger-generator · New: openapitools/openapi-generator-online · You can find our released artefact on maven central: Core: Old: <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-codegen</artifactId> </dependency> New: <dependency> <groupId>org.openapitools</groupId> <artifactId>openapi-generator</artifactId> </dependency> Cli: <dependency> <groupId>io.swag
Top answer
1 of 2
38

To use Swagger Codegen with Maven plug-in for OpenAPI 3.0.0 spec, you may consider using OpenAPI Generator instead (which is a community-driven version of Swagger Codegen).

<dependency>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>3.3.4</version>
</dependency>

Ref: https://github.com/OpenAPITools/openapi-generator#12---artifacts-on-maven-central

(please refer to the Q&A on why we forked Swagger Codegen)

2 of 2
20

The v3 swagger codegen maven plugin released April 2019 generates working Java client libraries from an OpenAPI 3.0 spec, I'm using this Maven pom.xml plugin config:

<plugin>
    <groupId>io.swagger.codegen.v3</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>3.0.8</version>
    <executions>
    ..

All the rest of the configuration and configOptions entries are unchanged from version 2.4.5. I had to replace the old annotation dependency with the following so the client code would compile:

    <dependency>
        <groupId>io.swagger.core.v3</groupId>
        <artifactId>swagger-annotations</artifactId>
        <version>2.0.8</version>
    </dependency>

Per request from @kozla13 below I added a complete POM example.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!-- This groupId will NOT allow deployment in LF -->
    <groupId>org.example.swaggerapi.client</groupId>
    <artifactId>swagger-client</artifactId>
    <name>Example</name>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <java.version>11</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <client.base.package.name>org.example.so</client.base.package.name>
    </properties>
    <dependencies>
        <!-- Required for Java 9 and later -->
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>2.0.8</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.1.10.RELEASE</version>
        </dependency>
        <!-- HTTP client: Spring RestTemplate -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.1.10.RELEASE</version>
        </dependency>
        <!-- JSON processing: jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.9</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.9.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>2.9.9</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.9.9</version>
        </dependency>
        <!-- test dependencies -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.3.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <!-- This 2019 version is required for OpenAPI 3 -->
                <groupId>io.swagger.codegen.v3</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>3.0.8</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/ric-plt-a1/a1/openapi.yaml</inputSpec>
                            <language>java</language>
                            <packageName>${client.base.package.name}</packageName>
                            <modelPackage>${client.base.package.name}.model</modelPackage>
                            <apiPackage>${client.base.package.name}.api</apiPackage>
                            <invokerPackage>${client.base.package.name}.invoker</invokerPackage>
                            <configOptions>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>${project.artifactId}</artifactId>
                                <artifactVersion>${project.version}</artifactVersion>
                                <library>resttemplate</library>
                                <java8>true</java8>
                                <dateLibrary>java8</dateLibrary>
                                <licenseName>Apache 2.0</licenseName>
                                <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>