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
2.2.1 - it was working in 2.1.6
https://github.com/amadeus-travel-innovation-sandbox/sandbox-content/blob/master/swagger.yml
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>
Clone and build https://github.com/tadhgpearson/swagger-maven-plugin-dependencies
I'm using Java 8 & Maven 3.3
Perhaps #3261 ?
Behaviour suggests the default is now using GSON + OK HTTP - maybe that's where the bug is?
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
?)
OK - I managed to resolve this looking through the code and provided the above pull request to update the documentation. Hope that helps!
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!
is there a way to still use jersy and ignore the new default GSON library?
@aparnarus: use the jersey1
switch, as documented in the readme.
Thank you! im not sure how i missed it - but yes that worked.
@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