When I try to run the generated gradle, some dependencies are missing. I get some errors like the following:
/path/File.java:xx: error: package org.openapitools.jackson.nullable does not exist
import org.openapitools.jackson.nullable.JsonNullableModule;
Which is solved by adding the following line to the dependencies section:
compile "org.openapitools:jackson-databind-nullable:0.2.1"
This is the configuration of the gradle task that generates the failing gradle script:
task openApiJavaClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
generatorName = "java"
inputSpec = specFile
outputDir = generatedSubproject
invokerPackage = "com.foo"
modelPackage = "com.foo"
configOptions = [
dateLibrary : "java8",
library : "native",
artifactId : "java-api-client",
artifactVersion: project.version,
java8 : "true",
]
systemProperties = [
modelDocs: "false"
]
}
javadoc {
failOnError = false
}
jar.dependsOn tasks.openApiJavaClient
4.2.3
N/A
./gradlew clean build
./gradlew clean build
It seems this issue was fixed in v4.1.2 but it happens again in v4.2.3:
https://github.com/OpenAPITools/openapi-generator/pull/3793
N/A
I am also facing this issue 馃憤
@jhandguy If you need a temporary workaround, you just have to add the following lines to the generated gradle project:
dependencies {
compile "org.openapitools:jackson-databind-nullable:0.2.1"
}
If you need to automate this task because the client project is automatically generated and built from other gradle parent project, you can include this within the task of the parent project that needs to use the openapi gradle subproject:
doFirst {
// Fix for issue: https://github.com/OpenAPITools/openapi-generator/issues/5690
def f = new File("$generatedSubproject/build.gradle")
f.append("""
dependencies {
compile "org.openapitools:jackson-databind-nullable:0.2.1"
}
""")
}
I also encountered the same issue with OpenAPI generator v4.3.0 in a Spring Boot project. It could be reproduced by using the Pet API and the following plugin configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<generatorName>spring</generatorName>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<java8>true</java8>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
So the same issue also applies to spring generator. I would be happy to create a separate bug report if needed.
@wing328 Given you merged the original fix for this (https://github.com/OpenAPITools/openapi-generator/pull/3793) do you know what happened to have it dropped? I'm using 4.3.0
I can fix this, but it might be better to know more about why the regression happened.
Should this issue also be assigned to someone?
I can fix this, but it might be better to know more about why the regression happened.
can you please submit a PR to start with?
would be great if you can use git bisect to identify the commit causing the issue?
moving forward, it will be better to test it in the CI so as to catch the issue moving forward.
Doing some more investigation, looking at the blame log it seems that the template snippet for compile "org.openapitools:jackson-databind-nullable:0.2.1" is still there on master (from https://github.com/OpenAPITools/openapi-generator/commit/ad6c8321621dd41e1dd7412cd00b12c6e480918) and was released in 4.3.0. Pulling the 4.3.0 JAR out of my Gradle cache and looking inside, the Java/build.gradle.mustache template is correct. Yet when generating Java code (using Gradle plugin id 'org.openapi.generator' version '4.3.0') the resulting build.gradle does not match the template at all.
I've created a sample project https://github.com/kierans/openapi-generator-java-sample
For those using Gradle here's a quick snippet to see what's on the buildscript classpath so that you can see what version of openapi JARs Gradle is using to generate the code
task dumpScriptClasspath {
doLast {
buildscript.configurations.classpath.each { println it }
}
}
This should be fix by #2901 .
In the attached PR, I add a property to remove org.openapitools:jackson-databind-nullable from classpath.
I also try to add this dependency in the generated build.gradle when it was missing.
I'm seeing this issue using 4.3.1. Was able to resolve by manually adding the respective dependency to the classpath.
nullable: true@gausnes : In fact, it is more than that.
The may objective of #2901 was to remove a jar (and also all associated imports) from the generated code. When I made this PR, I ensure that all dependencies was properly in the classpath (pom.xml or build.gradle) when you enable the property openApiNullable. In this case, I noticed that the dependencies were missing and I added.
In the future release of openapi-generator (the 5.0.0), this should be fix.
I'm playing around with latest version 4 and 5.0.0-beta2 and I hade to manually add the following dependencies for java and resttemplate:
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5'
compile group: 'com.squareup.okhttp', name: 'logging-interceptor', version: '2.7.5'
compile group: 'com.squareup.retrofit', name: 'retrofit', version: '1.9.0'
compile group: 'org.threeten', name: 'threetenbp', version: '1.4.0'
compile group: 'io.swagger.core.v3', name: 'swagger-annotations', version: '2.1.4'
compile group: 'io.gsonfire', name: 'gson-fire', version: '1.8.4'
compile group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'
Now I'm trying webclient instead of resttemplate and again dependencies are missing and I don't know which yet:
org.apache.commons.logging.*
org.springframework.core.*
org.springframework.http.*
org.springframework.util.*
org.springframework.web.*
reactor.core.*
I tested resttemplate in the latest master with petstore spec and could run mvn clean package, gradle build without issues.
@black-snow I've filed https://github.com/OpenAPITools/openapi-generator/pull/7777 to fix the missing dependency issue in Java webclient client
If there's still an issue with missing dependencies, please PM me via Slack channel, which can be found in the project's README.
Most helpful comment
@black-snow I've filed https://github.com/OpenAPITools/openapi-generator/pull/7777 to fix the missing dependency issue in Java
webclientclient