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

[BUG] Missing dependencies in java generator #5690

Closed
5 of 6 tasks
mariomac opened this issue Mar 24, 2020 · 22 comments
Closed
5 of 6 tasks

[BUG] Missing dependencies in java generator #5690

mariomac opened this issue Mar 24, 2020 · 22 comments

Comments

@mariomac
Copy link

mariomac commented Mar 24, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

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
openapi-generator version

4.2.3

OpenAPI declaration file content or url

N/A

Command line used for generation

./gradlew clean build

Steps to reproduce

./gradlew clean build

Related issues/PRs

It seems this issue was fixed in v4.1.2 but it happens again in v4.2.3:

#3793

Suggest a fix

N/A

@jhandguy
Copy link

jhandguy commented Apr 8, 2020

I am also facing this issue 👍

@mariomac
Copy link
Author

mariomac commented Apr 8, 2020

@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"
}
""")
    }

@egemenvardar
Copy link

egemenvardar commented Apr 19, 2020

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.

@kierans
Copy link
Contributor

kierans commented Apr 21, 2020

@wing328 Given you merged the original fix for this (#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?

@wing328
Copy link
Member

wing328 commented Apr 21, 2020

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.

@kierans
Copy link
Contributor

kierans commented May 4, 2020

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

@kierans
Copy link
Contributor

kierans commented May 4, 2020

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

@Patouche
Copy link
Contributor

Patouche commented May 5, 2020

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.

@gausnes
Copy link

gausnes commented Sep 2, 2020

I'm seeing this issue using 4.3.1. Was able to resolve by manually adding the respective dependency to the classpath.

#2901 appears to just be cleaning up this import is not used. Model generation is still failing if properties are flagged with nullable: true

@Patouche
Copy link
Contributor

Patouche commented Sep 2, 2020

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

@black-snow
Copy link

black-snow commented Sep 16, 2020

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:

  • GSON (I try 2.8.6)
  • swagger-annotations (I try 1.6.2)
  • findbugs / jsr305 (I try 3.0.2
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'

@black-snow
Copy link

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

@wing328
Copy link
Member

wing328 commented Oct 21, 2020

I tested resttemplate in the latest master with petstore spec and could run mvn clean package, gradle build without issues.

@wing328
Copy link
Member

wing328 commented Oct 21, 2020

@black-snow I've filed #7777 to fix the missing dependency issue in Java webclient client

@wing328
Copy link
Member

wing328 commented Nov 9, 2020

If there's still an issue with missing dependencies, please PM me via Slack channel, which can be found in the project's README.

@scothale
Copy link

Could this issue be reworded to "Plugin tries to compile the separate generated project when it should only generate the project"?

@black-snow
Copy link

@scothale could you elaborate that?

@bodograumann
Copy link
Contributor

Just wanted to note, that this issue might still occur in the JavaJaxRS code generator, when no type: … field is given for a property of a schema. The JsonNullable is not actually used in code, but it is imported and no dependency for it is added to the pom.xml.
We just added the missing type and everything was fine again.

@rupert-jung-mw
Copy link

Still facing package org.openapitools.jackson.nullable does not exist with 7.2.0

@wiesnery
Copy link
Contributor

wiesnery commented Mar 4, 2024

This is still an issue in 7.3.0 but can be solved with the property: openApiNullable=false

@durcon
Copy link

durcon commented Mar 27, 2024

Why is this issue closed? The bug is still there. Although openApiNullable=false seems to work.

@winrid
Copy link

winrid commented Apr 18, 2024

With openApiNullable=false it still imports import com.fasterxml.jackson.databind.util.StdDateFormat; which is not defined in dependencies.

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