Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Cannot build code generated by Maven plugin #4298

Closed
tadhgpearson opened this issue Nov 30, 2016 · 7 comments
Closed

[Java] Cannot build code generated by Maven plugin #4298

tadhgpearson opened this issue Nov 30, 2016 · 7 comments

Comments

@tadhgpearson
Copy link
Contributor

tadhgpearson commented Nov 30, 2016

Description

I'm using the Maven plugin to generate Java code. Following the generation, I get errors compiling the generated code such as:

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

I'm surprised because I expect Jersey client 1.18. JSON processing: Jackson 2.4.2 to be used, as documented in the readme - why do I need GSON or OKIO. If I do, I can't find which dependencies I would need to add to resolve this issue - I am using the examples in the swagger-maven-plugin documentation, but the build is still failing

Swagger-codegen version

2.2.1 - it was working in 2.1.6

Swagger declaration file content or url

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

Command line used for generation

Codegen config

						<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 and properties

<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>
Steps to reproduce

Clone and build https://github.com/tadhgpearson/swagger-maven-plugin-dependencies
I'm using Java 8 & Maven 3.3

Related issues

Perhaps #3261 ?

Suggest a Fix

Behaviour suggests the default is now using GSON + OK HTTP - maybe that's where the bug is?

@tadhgpearson
Copy link
Contributor Author

Aha - the clue is in JavaClientCodegen:56 which was updated in #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");

If you want to keep this as the default (I prefer Jackson / Jersey, but that's just my little opinion), then the maven codegen examples need to be updated, and the documentation should tell me how I can now invoke what used to be the default option (is that jersey1?)

@tadhgpearson
Copy link
Contributor Author

OK - I managed to resolve this looking through the code and provided the above pull request to update the documentation. Hope that helps!

@aparnarus
Copy link

I recently updated from 2.1.6 to 2.2.1 as i needed the new "templateDirectory" feature that works in 2.2.1. but as soon as i did that i get same complier errors. how did you resolve this? help!

@aparnarus
Copy link

is there a way to still use jersy and ignore the new default GSON library?

@tadhgpearson
Copy link
Contributor Author

@aparnarus: use the jersey1 switch, as documented in the readme.

@aparnarus
Copy link

Thank you! im not sure how i missed it - but yes that worked.

@AntimoV123
Copy link

AntimoV123 commented Dec 4, 2019

@aparnarus: use the jersey1 switch, as documented in the readme.

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

it solved for me

many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants