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

Failed to generate openapi when the project using jackson-module-kotlin. #3278

Closed
Yushihu opened this issue Dec 6, 2023 · 3 comments
Closed

Comments

@Yushihu
Copy link

Yushihu commented Dec 6, 2023

I found out that it works well with gradle. So I update the maven version.

I was building an APP with Kotlin. Something wrong while executing the goal "openapi". It says "Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath". I found out that it happens when I involve "jackson-module-kotlin".
I'm not sure if it related with Remove kotlin-reflect and replace it with kotlinx-metadata-jvm.
Platform
kotlin 1.9.10
jooby 3.0.6
jackson 2.16.0
Maven 3.9.5
Reproduce:
Add those dependences to a Jooby project with OpenAPI supported.

    <dependency>
      <groupId>io.jooby</groupId>
      <artifactId>jooby-jackson</artifactId>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.module</groupId>
      <artifactId>jackson-module-kotlin</artifactId>
      <version>2.16.0</version>
    </dependency>

example code:

package app

import io.jooby.kt.Kooby
import io.jooby.kt.runApp
import io.jooby.netty.NettyServer
import io.jooby.OpenAPIModule
import io.jooby.jackson.JacksonModule

class App: Kooby({
  install(NettyServer())
  install(OpenAPIModule())
  install(JacksonModule())

  get("/") {
    Foo("Welcome to Jooby!")
  }
})

fun main(args: Array<String>) {
  runApp(args, ::App)
}

class Foo(val value: String)

Trigger the openapi goal.
mvn process-classes

Traceback:

[ERROR] Failed to execute goal io.jooby:jooby-maven-plugin:3.0.6:openapi (default-cli) on project testapp: execution of openapi resulted in exception: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal io.jooby:jooby-maven-plugin:3.0.6:openapi (default-cli) on project testapp: execution of openapi resulted in exception at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:347) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163) at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:910) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283) at org.apache.maven.cli.MavenCli.main (MavenCli.java:206) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke (Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348) at org.codehaus.classworlds.Launcher.main (Launcher.java:47) Caused by: org.apache.maven.plugin.MojoFailureException: execution of openapi resulted in exception at io.jooby.maven.BaseMojo.execute (BaseMojo.java:91) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163) at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:910) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283) at org.apache.maven.cli.MavenCli.main (MavenCli.java:206) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke (Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348) at org.codehaus.classworlds.Launcher.main (Launcher.java:47) Caused by: kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath at kotlin.jvm.internal.ClassReference.error (ClassReference.kt:88) at kotlin.jvm.internal.ClassReference.getConstructors (ClassReference.kt:21) at kotlin.reflect.jvm.ReflectJvmMapping.getKotlinFunction (ReflectJvmMapping.kt:177) at com.fasterxml.jackson.module.kotlin.KotlinNamesAnnotationIntrospector.findKotlinParameterName (KotlinNamesAnnotationIntrospector.kt:127) at com.fasterxml.jackson.module.kotlin.KotlinNamesAnnotationIntrospector.findImplicitPropertyName (KotlinNamesAnnotationIntrospector.kt:76) at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.findImplicitPropertyName (AnnotationIntrospectorPair.java:488) at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.findImplicitPropertyName (AnnotationIntrospectorPair.java:488) at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.findImplicitPropertyName (AnnotationIntrospectorPair.java:488) at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addCreatorParam (POJOPropertiesCollector.java:706) at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addCreatorParam (POJOPropertiesCollector.java:695) at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addCreators (POJOPropertiesCollector.java:644) at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll (POJOPropertiesCollector.java:451) at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor (POJOPropertiesCollector.java:286) at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueMethod (POJOPropertiesCollector.java:412) at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueMethod (BasicBeanDescription.java:252) at io.swagger.v3.core.jackson.ModelResolver.findJsonValueType (ModelResolver.java:1023) at io.swagger.v3.core.jackson.ModelResolver.resolve (ModelResolver.java:401) at io.swagger.v3.core.jackson.AbstractModelConverter.resolve (AbstractModelConverter.java:52) at io.jooby.internal.openapi.ModelConverterExt.resolve (ModelConverterExt.java:43) at io.swagger.v3.core.jackson.AbstractModelConverter.resolve (AbstractModelConverter.java:52) at io.jooby.internal.openapi.ModelConverterExt.resolve (ModelConverterExt.java:43) at io.swagger.v3.core.jackson.AbstractModelConverter.resolve (AbstractModelConverter.java:52) at io.jooby.internal.openapi.ModelConverterExt.resolve (ModelConverterExt.java:43) at io.swagger.v3.core.jackson.AbstractModelConverter.resolve (AbstractModelConverter.java:52) at io.jooby.internal.openapi.ModelConverterExt.resolve (ModelConverterExt.java:43) at io.swagger.v3.core.converter.ModelConverterContextImpl.resolve (ModelConverterContextImpl.java:97) at io.swagger.v3.core.converter.ModelConverters.resolveAsResolvedSchema (ModelConverters.java:153) at io.swagger.v3.core.converter.ModelConverters.readAllAsResolvedSchema (ModelConverters.java:143) at io.swagger.v3.core.converter.ModelConverters.readAllAsResolvedSchema (ModelConverters.java:139) at io.jooby.internal.openapi.ParserContext.schema (ParserContext.java:258) at io.jooby.internal.openapi.ParserContext.schema (ParserContext.java:335) at io.jooby.internal.openapi.ParserContext.schema (ParserContext.java:314) at io.jooby.internal.openapi.RouteParser.parseSchema (RouteParser.java:267) at io.jooby.internal.openapi.RouteParser.checkResponse (RouteParser.java:139) at io.jooby.internal.openapi.RouteParser.checkResponses (RouteParser.java:133) at io.jooby.internal.openapi.RouteParser.parse (RouteParser.java:120) at io.jooby.openapi.OpenAPIGenerator.generate (OpenAPIGenerator.java:177) at io.jooby.maven.OpenAPIMojo.doExecute (OpenAPIMojo.java:72) at io.jooby.maven.BaseMojo.execute (BaseMojo.java:87) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163) at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:910) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283) at org.apache.maven.cli.MavenCli.main (MavenCli.java:206) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke (Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348) at org.codehaus.classworlds.Launcher.main (Launcher.java:47)

@jknack
Copy link
Member

jknack commented Dec 6, 2023

can you add a minimal example to reproduce it?

@Yushihu
Copy link
Author

Yushihu commented Dec 7, 2023

Sorry for the late response.
Here is the example.

package app

import io.jooby.kt.Kooby
import io.jooby.kt.runApp
import io.jooby.netty.NettyServer
import io.jooby.OpenAPIModule
import io.jooby.jackson.JacksonModule

class App: Kooby({
  install(NettyServer())
  install(OpenAPIModule())
  install(JacksonModule())

  get("/") {
    Foo("Welcome to Jooby!")
  }
})

fun main(args: Array<String>) {
  runApp(args, ::App)
}

class Foo(val value: String)

@jknack jknack closed this as completed in 966a00c Feb 18, 2024
@jknack jknack added this to the 3.0.8 milestone Feb 18, 2024
@jknack
Copy link
Member

jknack commented Feb 18, 2024

@Yushihu finally look into this. There isn't much jooby can do here, but it is easy to fix. Go to your pom.xml find the openapi plugin setup and add the kotlin-reflect dependency:

<plugin>
        <groupId>io.jooby</groupId>
        <artifactId>jooby-maven-plugin</artifactId>
        <version>${jooby.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>openapi</goal>
            </goals>
            <configuration>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
            <version>${kotlin.version}</version>
          </dependency>
        </dependencies>
      </plugin>

I added these lines to jooby-cli for maven kotlin projects.

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

2 participants