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

ClassNotFoundException: io.swagger.v3.oas.models.OpenAPI on Gradle's generateOpenapi #845

Open
gavenkoa opened this issue Jun 6, 2022 · 0 comments

Comments

@gavenkoa
Copy link

gavenkoa commented Jun 6, 2022

With Gradle 7.4:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "io.crnk:crnk-gen-gradle:${crnkVersion}"
        classpath "org.reflections:reflections:0.10.2"
    }
}

apply plugin: 'crnk-gen'
crnkGen {
    runtime {
        // Gradle classpath configuration to use
        configuration = 'runtimeClasspath'
    }

    openapi {
        enabled = true
        genDir = file('${projectRoot}/build/openapi')
    }
}

gradle generateOpenapi fails as:

> Task :generateOpenapi FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4/userguide/command_line_interface.html#sec:command_line_warnings
1 actionable task: 1 executed
Exception in thread "main" java.lang.IllegalStateException: failed to generate class io.crnk.gen.openapi.OpenAPIGeneratorModule, source=null
	at io.crnk.gen.gradle.task.ForkedGeneratorMain.main(ForkedGeneratorMain.java:37)
Caused by: java.lang.NoClassDefFoundError: Lio/swagger/v3/oas/models/OpenAPI;
	at java.base/java.lang.Class.getDeclaredFields0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3061)
	at java.base/java.lang.Class.getDeclaredFields(Class.java:2248)
	at com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector._findFields(AnnotatedFieldCollector.java:73)
	at com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collect(AnnotatedFieldCollector.java:48)
	at com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collectFields(AnnotatedFieldCollector.java:43)
	at com.fasterxml.jackson.databind.introspect.AnnotatedClass._fields(AnnotatedClass.java:371)
	at com.fasterxml.jackson.databind.introspect.AnnotatedClass.fields(AnnotatedClass.java:343)
	at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addFields(POJOPropertiesCollector.java:494)
	at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:421)
	at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getPropertyMap(POJOPropertiesCollector.java:386)
	at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getProperties(POJOPropertiesCollector.java:233)
	at com.fasterxml.jackson.databind.introspect.BasicBeanDescription._properties(BasicBeanDescription.java:164)
	at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findProperties(BasicBeanDescription.java:239)
	at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._findCreatorsFromProperties(BasicDeserializerFactory.java:328)
	at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._constructDefaultValueInstantiator(BasicDeserializerFactory.java:272)
	at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findValueInstantiator(BasicDeserializerFactory.java:223)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:261)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:150)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:415)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:350)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
	at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
	at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:642)
	at com.fasterxml.jackson.databind.ObjectReader._prefetchRootDeserializer(ObjectReader.java:2376)
	at com.fasterxml.jackson.databind.ObjectReader.<init>(ObjectReader.java:193)
	at com.fasterxml.jackson.databind.ObjectMapper._newReader(ObjectMapper.java:754)
	at com.fasterxml.jackson.databind.ObjectMapper.readerFor(ObjectMapper.java:4130)
	at io.crnk.gen.gradle.task.ForkedGeneratorMain.main(ForkedGeneratorMain.java:26)
Caused by: java.lang.ClassNotFoundException: io.swagger.v3.oas.models.OpenAPI
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 30 more

FAILURE: Build failed with an exception.

I think new Gradle versions handle plugin classpath differently... Adding

 classpath "io.swagger.core.v3:swagger-project:2.2.0"

doesn't solve the problem. May be another version is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant