1

UPDATE: I see on this URL https://repo1.maven.org/maven2/io/swagger/swagger-codegen-maven-plugin/ that the only version of swagger codegen is 3.0.0-rc1

I'm trying to build a REST API with Java/SpringBoot and using the swagger-codegen plugin. I am able to use the plugin version of swagger codegen 2.3.1, it downloads fine for some reason.

However, I am trying to use Open api spec 3.0, and 2.3.1 would NOT work, and I found on Stackoverflow people saying I need to use 3.X.X of swagger-codegen to use open api spec 3.0.

So I changed the plugin version to 3.0.0, and 3.0.25 and many different versions but it keeps failing no matter what I do:

[ERROR] Plugin io.swagger:swagger-codegen-maven-plugin:3.0.0 or one of its dependencies could not be resolved: Could not find artifact io.swagger:swagger-codegen-maven-plugin:jar:3.0.0 in central (https://repo1.maven.org/maven2) -> [Help 1]
org.apache.maven.plugin.PluginResolutionException: Plugin io.swagger:swagger-codegen-maven-plugin:3.0.0 or one of its dependencies could not be resolved: Could not find artifact io.swagger:swagger-codegen-maven-plugin:jar:3.0.0 in central (https://repo1.maven.org/maven2)

I was playing around with my settings.xml file and pom.xml but nothing seems to work. I'm confused because this JAR is on maven central, so it should be easily downloaded, correct? Also, I tried adding it as both a dependency AND plugin, and the dependency seems to be downloaded fine (even version 3.0.25), its just the plugin that fails all the time.

I will say I'm on a work computer being a proxy, but I added that info to the settings.xml - could that be related?

my pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.mydomain.me</groupId>
    <artifactId>my-api</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>My API</name>
    <description>Version 2.0 of my API</description>
    <properties>
        <java.version>11</java.version>
    </properties>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <name>Maven Central</name>
            <layout>default</layout>
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.swagger.codegen.v3</groupId>
            <artifactId>swagger-codegen-cli</artifactId>
            <version>3.0.25</version>
        </dependency>
    </dependencies>

    <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>3.0.25</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
                            <output>${project.basedir}/target/generated-sources</output>
                            <language>java</language>
                            <configOptions>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

ennth
  • 1,698
  • 5
  • 31
  • 63

2 Answers2

0

I don't know if it helps, but I was facing a similar problem. The thing is that the dependency was downloaded to the .m2 folder, but it was not reflecting on Maven Dependencies inside Libraries in Eclipse. So I ran this command inside the project where I needed the plugin: mvn swagger-codegen:generate. And then the files I needed were generated. I have no idea why the plugin wasn't being showed in Eclipse, but somehow it was there, hidden.

Amir_P
  • 8,322
  • 5
  • 43
  • 92
Nyc
  • 1
  • 1
  • 1
0

The groupId of swagger-codegen-maven-plugin has changed. Should be:

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