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处理:如自述文件中所述,将使用Jackson 2.4.2_-为什么需要GSON或OKIO。 如果可以,我找不到解决此问题所需添加的依赖项-我正在使用swagger-maven-plugin文档中的示例,但是构建仍然失败

Swagger-Codegen版本

2.2.1-它在2.1.6中工作

昂首阔步的声明文件内容或网址

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
我正在使用Java 8和Maven 3.3

相关问题

也许#3261吗?

建议修复

行为表明默认值现在使用GSON + OK HTTP-也许这是错误所在?

Question Swagger Codegen Maven Plugin

所有7条评论

啊哈-线索在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");

如果要将其保留为默认值(我更喜欢Jackson / Jersey,但这只是我的看法),则需要更新Maven代码生成示例,并且文档应告诉我如何现在可以调用以前的代码。默认选项(是jersey1吗?)

好的-我设法通过代码解决了这个问题,并提供了上述拉取请求来更新文档。 希望能有所帮助!

我最近从2.1.6更新到2.2.1,因为我需要在2.2.1中可用的新“ templateDirectory”功能。 但是,一旦我这样做,我就会得到同样的编译器错误。 您是如何解决的? 帮助!

有没有办法仍然使用jersy并忽略新的默认GSON库?

@aparnarus :使用jersey1开关,如自述文件中所述。

谢谢! 林不知道我怎么想念它-但是的,有效的。

@aparnarus :使用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 等级