Swagger-codegen: [Java] Mavenプラグインによって生成されたコードをビルドできません

作成日 2016年11月30日  ·  7コメント  ·  ソース: swagger-api/swagger-codegen

説明

Mavenプラグインを使用してJavaコードを生成しています。 生成後、次のような生成されたコードのコンパイル中にエラーが発生します。

package com.google.gson.annotations does not exist
package okio does not exist

_Jerseyクライアント1.18を期待しているので驚いています。 JSON処理:readmeに記載されているように、Jackson2.4.2_を使用します-なぜGSONまたはOKIOが必要なのですか。 そうした場合、この問題を解決するために追加する必要のある依存関係が見つかりません-swagger-maven-pluginドキュメントの例を使用していますが、ビルドはまだ失敗しています

Swagger-codegenバージョン

2.2.1-2.1.6で動作していました

Swagger宣言ファイルの内容またはURL

https://github.com/amadeus-travel-innovation-sandbox/sandbox-content/blob/master/swagger.yml

生成に使用されるコマンドライン

Codegen構成

                        <configuration>
                            <inputSpec>https://raw.githubusercontent.com/amadeus-travel-innovation-sandbox/sandbox-content/master/swagger.yml</inputSpec>
                            <language>java</language>
                            <configOptions>
                               <dateLibrary>joda</dateLibrary>
                            </configOptions>
                            <output>${project.build.directory}/generated-sources/swagger</output>
                        </configuration>

依存関係とプロパティ

<dependencies>
        <!-- dependencies are needed for the client being generated -->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>${swagger-annotations-version}</version>
        </dependency>

        <!-- HTTP client: jersey-client -->
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${jersey-version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>${jersey-version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>2.22.1</version>
        </dependency>

        <!-- JSON processing: jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-joda</artifactId>
            <version>2.1.5</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>${jodatime-version}</version>
        </dependency>

        <!-- Base64 encoding that works in both JVM and Android -->
        <dependency>
            <groupId>com.brsanthu</groupId>
            <artifactId>migbase64</artifactId>
            <version>2.2</version>
        </dependency>
        <!-- test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit-version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <swagger-annotations-version>1.5.0</swagger-annotations-version>
        <jersey-version>2.12</jersey-version>
        <jackson-version>2.4.2</jackson-version>
        <jodatime-version>2.3</jodatime-version>
        <maven-plugin-version>1.0.0</maven-plugin-version>
        <junit-version>4.8.1</junit-version>
    </properties>
再現する手順

https://github.com/tadhgpearson/swagger-maven-plugin-dependenciesのクローンを作成してビルドし
Java8とMaven3.3を使用しています

関連する問題

おそらく#3261?

修正を提案する

動作は、デフォルトがGSON + OK HTTPを使用していることを示唆しています-おそらくそれがバグの場所ですか?

Question Swagger Codegen Maven Plugin

全てのコメント7件

Aha-手がかりはJavaClientCodegen:56あり、#3919で更新されました

CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use"); libraryOption.setEnum(supportedLibraries); // set okhttp-gson as the default libraryOption.setDefault("okhttp-gson"); cliOptions.add(libraryOption); setLibrary("okhttp-gson");

これをデフォルトのままにしておきたい場合(私はジャクソン/ジャージーが好きですが、それは私の小さな意見です)、maven codegenの例を更新する必要があり、ドキュメントは、以前のものを呼び出す方法を教えてくれるはずですデフォルトのオプション(それはjersey1ですか?)

OK-コードを調べてこれを解決し、ドキュメントを更新するために上記のプルリクエストを提供しました。 お役に立てば幸いです。

2.2.1で機能する新しい「templateDirectory」機能が必要だったため、最近2.1.6から2.2.1に更新しました。 しかし、それを行うとすぐに、同じコンパイラエラーが発生します。 これをどのように解決しましたか? 助けて!

まだjersyを使用して、新しいデフォルトのGSONライブラリを無視する方法はありますか?

@aparnarus :readmeに記載されているように、 jersey1スイッチを使用します。

ありがとうございました! どのように私がそれを逃したのかわかりません-しかし、はい、それはうまくいきました。

@aparnarus :readmeに記載されているように、 jersey1スイッチを使用します。

<build> <plugins> <plugin> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>2.3.1</version> <executions> <execution> <goals> <goal>generate</goal> </goals> <configuration> <inputSpec>/src/main/resources/swagger.json</inputSpec> <language>java</language> <output></output> <apiPackage>it.eng.sil.scoop</apiPackage> <modelPackage>it.eng.sil.ws.scoop.client.model</modelPackage> <generateModels>true</generateModels> <generateApis>false</generateApis> <generateApiTests>false</generateApiTests> <generateApiDocumentation>false</generateApiDocumentation> <generateSupportingFiles>false</generateSupportingFiles> <generateModelDocumentation>false</generateModelDocumentation> **<library>jersey1</library>** <configOptions> <dateLibrary>java8</dateLibrary> <sourceFolder>src/main/java</sourceFolder> </configOptions> </configuration> </execution> </executions> </plugin> </plugins> </build>

それは私のために解決しました

どうもありがとう

このページは役に立ちましたか?
0 / 5 - 0 評価