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

Gradle plugin crashes with Jackson-related stacktrace #1339

Closed
Hes-Siemelink opened this issue Jan 6, 2023 · 3 comments · Fixed by #1342
Closed

Gradle plugin crashes with Jackson-related stacktrace #1339

Hes-Siemelink opened this issue Jan 6, 2023 · 3 comments · Fixed by #1342
Labels
bug Something isn't working plugin/gradle
Milestone

Comments

@Hes-Siemelink
Copy link

I am trying the gradle plugin but it doesn't work out of the box

Setup

  • Building plugin from main / 3.1.2-SNAPSHOT
  • Gradle 7.5.1
  • Added plugin to gradle project using
plugins {
  id("io.smallrye.openapi") version "3.1.2-SNAPSHOT"
}

generateOpenApiSpec {
  scanPackages = ["com.myproject"]
}
  • Build using gradle clean build --stacktrace

Behavior

In stead of succeeding, the build fails with the following stack trace (snippet):

Caused by: java.lang.NoSuchMethodError: 'com.fasterxml.jackson.core.io.ContentReference com.fasterxml.jackson.dataformat.yaml.YAMLFactory._createContentReference(java.lang.Object)'
        at com.fasterxml.jackson.dataformat.yaml.YAMLFactory.createGenerator(YAMLFactory.java:441)
        at com.fasterxml.jackson.dataformat.yaml.YAMLFactory.createGenerator(YAMLFactory.java:15)
        at com.fasterxml.jackson.databind.ObjectWriter.createGenerator(ObjectWriter.java:703)
        at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:1086)
        at io.smallrye.openapi.runtime.io.OpenApiSerializer.serialize(OpenApiSerializer.java:48)
        at io.smallrye.openapi.gradleplugin.SmallryeOpenApiTask.write(SmallryeOpenApiTask.java:298)
        at io.smallrye.openapi.gradleplugin.SmallryeOpenApiTask.generate(SmallryeOpenApiTask.java:119)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

This can be traced down to a different version of jackson-core being used (that has the JSONFactory class) vs jackson-dataformat-yaml (that has `YAMLFactory, calling the _createContentReference() method).

Plugin classpath:

> Task :public:api:buildEnvironment

------------------------------------------------------------
Project ':public:api'
------------------------------------------------------------

classpath
\--- io.smallrye.openapi:io.smallrye.openapi.gradle.plugin:3.1.2-SNAPSHOT
     \--- io.smallrye:smallrye-open-api-gradle-plugin:3.1.2-SNAPSHOT
          +--- io.smallrye:smallrye-open-api-core:3.1.2-SNAPSHOT
          |    +--- org.eclipse.microprofile.openapi:microprofile-openapi-api:3.1
          |    +--- org.eclipse.microprofile.config:microprofile-config-api:3.0
          |    +--- com.fasterxml.jackson.core:jackson-core:2.13.4
          |    |    \--- com.fasterxml.jackson:jackson-bom:2.13.4
          |    |         +--- com.fasterxml.jackson.core:jackson-annotations:2.13.4 (c)
          |    |         +--- com.fasterxml.jackson.core:jackson-core:2.13.4 (c)
          |    |         +--- com.fasterxml.jackson.core:jackson-databind:2.13.4 -> 2.13.4.2 (c)
          |    |         \--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.4 (c)
          |    +--- com.fasterxml.jackson.core:jackson-databind:2.13.4.2
          |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.4
          |    |    |    \--- com.fasterxml.jackson:jackson-bom:2.13.4 (*)
          |    |    +--- com.fasterxml.jackson.core:jackson-core:2.13.4 (*)
          |    |    \--- com.fasterxml.jackson:jackson-bom:2.13.4 (*)
          |    +--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.4
          |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.13.4 -> 2.13.4.2 (*)
          |    |    +--- org.yaml:snakeyaml:1.31
          |    |    +--- com.fasterxml.jackson.core:jackson-core:2.13.4 (*)
          |    |    \--- com.fasterxml.jackson:jackson-bom:2.13.4 (*)
          |    +--- io.smallrye:jandex:3.0.5
          |    \--- org.jboss.logging:jboss-logging:3.5.0.Final
          +--- io.smallrye:smallrye-open-api-jaxrs:3.1.2-SNAPSHOT
          |    +--- io.smallrye:smallrye-open-api-core:3.1.2-SNAPSHOT (*)
          |    \--- org.jboss.logging:jboss-logging:3.5.0.Final
          +--- io.smallrye:smallrye-open-api-spring:3.1.2-SNAPSHOT
          |    +--- io.smallrye:smallrye-open-api-core:3.1.2-SNAPSHOT (*)
          |    \--- org.jboss.logging:jboss-logging:3.5.0.Final
          \--- io.smallrye:smallrye-open-api-vertx:3.1.2-SNAPSHOT
               +--- io.smallrye:smallrye-open-api-core:3.1.2-SNAPSHOT (*)
               \--- org.jboss.logging:jboss-logging:3.5.0.Final

(c) - dependency constraint
(*) - dependencies omitted (listed previously)

Workaround

Works when I revert to Jackson 2.12.0 in the main pom.xml of the SmallRye project and rebuild the plugin.

MikeEdgar added a commit to MikeEdgar/smallrye-open-api that referenced this issue Jan 7, 2023
Fixes smallrye#1339

Signed-off-by: Michael Edgar <michael@xlate.io>
MikeEdgar added a commit to MikeEdgar/smallrye-open-api that referenced this issue Jan 7, 2023
Fixes smallrye#1339

Signed-off-by: Michael Edgar <michael@xlate.io>
@MikeEdgar MikeEdgar added the bug Something isn't working label Jan 7, 2023
@MikeEdgar MikeEdgar added this to the 3.1.2 milestone Jan 7, 2023
@Hes-Siemelink
Copy link
Author

Was not fixed by #1342

Plugin does work with a sample project.

Since gradle buildEnvironment gives the correct plugin class path it most probably either a misconfiguration in the project or an error in how gradle loads the classpath and leaves a different jackson version lingering somewhere.

@MikeEdgar
Copy link
Member

@Hes-Siemelink , if you can provide a reproducer project that has this problem, I could help look at it. As you've said, it's may not an issue with the plugin, but the additional Jackson version on the classpath. If you enable debug logging when running the plugin, you should see statements like this:

Adding X to annotation scanner class loader

where X is the jar file being added. That might help confirm what is present during the scan.

@Hes-Siemelink
Copy link
Author

This is what I see

 cat build.log | grep jackson | grep "annotation scanner"
2023-01-16T17:03:16.439+0100 [DEBUG] [org.gradle.api.Task] Adding /Users/hsiemelink/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.14.1/7a07bc535ccf0b7f6929c4d0f2ab9b294ef7c4a3/jackson-core-2.14.1.jar to annotation scanner class loader
2023-01-16T17:03:16.439+0100 [DEBUG] [org.gradle.api.Task] Adding /Users/hsiemelink/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.14.1/268524b9056cae1211b9f1f52560ef19347f4d17/jackson-databind-2.14.1.jar to annotation scanner class loader
2023-01-16T17:03:16.439+0100 [DEBUG] [org.gradle.api.Task] Adding /Users/hsiemelink/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.14.1/2a6ad504d591a7903ffdec76b5b7252819a2d162/jackson-annotations-2.14.1.jar to annotation scanner class loader

Looks good to me. I will ping you if I find something that points to the plugin... For now doesn't seem to be the first candidate of causing the error.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plugin/gradle
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants