1

更新: この URL https://repo1.maven.org/maven2/io/swagger/swagger-codegen-maven-plugin/を見る と、swagger codegen の唯一のバージョンは 3.0.0-rc1 です。

Java/SpringBoot と swagger-codegen プラグインを使用して REST API を構築しようとしています。swagger codegen 2.3.1 のプラグイン バージョンを使用できます。何らかの理由で正常にダウンロードされます。

ただし、私は Open API 仕様 3.0 を使用しようとしていますが、2.3.1 は機能しません。Stackoverflow の人々が、Open API 仕様 3.0 を使用するには 3.XX の swagger-codegen を使用する必要があると言っているのを見つけました。

そのため、プラグインのバージョンを 3.0.0、3.0.25、および多くの異なるバージョンに変更しましたが、何をしても失敗し続けます。

[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)

settings.xml ファイルと pom.xml をいじっていましたが、何も機能していないようです。この JAR は Maven Central にあるので混乱しています。簡単にダウンロードできるはずですよね?また、依存関係とプラグインの両方として追加しようとしましたが、依存関係は正常にダウンロードされているようで (バージョン 3.0.25 でも)、常に失敗するプラグインです。

私はプロキシである職場のコンピューターにいると言いますが、その情報をに追加しましたsettings.xml-それは関連している可能性がありますか?

私の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>

4

1 に答える 1

0

参考になるかどうかわかりませんが、私も似たような問題に直面していました。問題は、依存関係がフォルダーにダウンロードされたことですが.m2、Eclipse のライブラリ内の Maven 依存関係に反映されていませんでした。そこで、プラグインが必要なプロジェクト内でこのコマンドを実行しました: mvn swagger-codegen:generate. そして、必要なファイルが生成されました。プラグインが Eclipse に表示されなかった理由はわかりませんが、どういうわけかそこに隠されていました。

于 2021-10-27T19:39:58.043 に答える