[Java] Gradle wrapper is unusable: Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Description
I am trying to generate client bindings from an OpenAPI YAML spec and then use that with the generated Gradle Wrapper.
The issue is that the gradle/wrapper/gradle-wrapper.jar file has zero size rendering the gradlew script unusable.
Swagger-codegen version
3.0.8
Swagger declaration file content or url
https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
Command line used for generation
java -jar /tmp/swagger-codegen-cli-3.0.8.jar generate -i /tmp/pet.yaml -l java -o /tmp/java
Steps to reproduce
- Download the pet store sample YAML definition (https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml) as
/tmp/pet.yaml - Run the generator:
java -jar /tmp/swagger-codegen-cli-3.0.8.jar generate -i /tmp/pet.yaml -l java -o /tmp/java - Make
gradlewexecutable:chmod +x /tmp/java/gradlew - Try to run a Gradle command using the generated wrapper:
cd /tmp/java && ./gradlew --version
Expected result: the Gradle version is printed out.
Actual result:
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
Also doing a ls -la gradle/wrapper:
...
-rw-rw-r-- 1 ailiev ailiev 0 Mai 3 13:22 gradle-wrapper.jar
...
Suggest a fix/enhancement
The cause seems to be that the generator tries to copy the file from handlebars/Java/gradle-wrapper.jar, while the actual file is in Java/gradle-wrapper.jar. There is a warning in the generator output indicating this:
13:15:43.889 [Thread-1] WARN io.swagger.codegen.v3.DefaultGenerator - can't open handlebars/Java/gradle-wrapper.jar for input
Not sure what the correct solution would be though.
I am also experiencing this issue ☝️
I'm also experiencing this
Yep, running into this as well. Iff i pass -Dmodels it works as expected, but if i pass -Dapis it fails. this seems like a fairly major problem that clients can't be generated, no?
I am seeing this error too, with codegen version 3.0.13
Thanks for reporting this, fixed in swagger-api/swagger-codegen-generators#555