Swagger-codegen: [ANY] Maven build fails for client generation and no jar file is created.

Created on 13 Dec 2018  路  14Comments  路  Source: swagger-api/swagger-codegen

Description

I'm following the Readme file (Getting Started) to generate a PHP client. The following error happens after running mvn clean package

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] swagger-codegen-project 3.0.3 ...................... SUCCESS [  9.209 s]
[INFO] swagger-codegen (core library) ..................... FAILURE [01:08 min]
[INFO] swagger-codegen (executable) ....................... SKIPPED
[INFO] swagger-codegen (maven-plugin) ..................... SKIPPED
[INFO] swagger-generator 3.0.3 ............................ SKIPPED
,
       "summary": "Finds Pets by tags",
       "description": "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

The swagger-codegen-cli.jar file does not get generated, so running the next command:
```
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate
-i http://petstore.swagger.io/v2/swagger.json
-l php
-o /var/tmp/php_api_client


Error: Unable to access jarfile modules/swagger-codegen-cli/target/swagger-codegen-cli.jar

<!-- describe what is the question, suggestion or issue and why this is a problem for you. -->

##### Swagger-codegen version
ANY
<!-- which version of swagger-codegen are you using, is it a regression? -->

##### Swagger declaration file content or url
ANY
<!-- if it is a bug, a json or yaml that produces it.
If you post the code inline, please wrap it with
```yaml
(here your code)

(for YAML code) or

(here your code)

(for JSON code), so it becomes more readable. If it is longer than about ten lines,
please create a Gist (https://gist.github.com) or upload it somewhere else and
link it here.
-->

Command line used for generation
git clone https://github.com/swagger-api/swagger-codegen
cd swagger-codegen
mvn clean package
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
   -i http://petstore.swagger.io/v2/swagger.json \
   -l php \
   -o /var/tmp/php_api_client 
Related issues/PRs


https://github.com/swagger-api/swagger-codegen/issues/8734

Most helpful comment

For Ubuntu 18.04 with openjdk version "10.0.2", I resolved this issue by doing the following steps:

Installing openjdk 8:
sudo apt install openjdk-8-jdk

Use the openjdk 8 instead of the default one:
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/ mvn clean package and it will work!

All 14 comments

hello @sergio-alifano , i just checked this and worked find for me. can you please try again? in case it's still failure, please share more details about the build failure.

Hi @HugoMario, thanks for checking.
Unfortunately, I'm still getting the error. I tried on 2 different machines with the same result (windows10 and MacOS). There's clearly something that I'm missing if this is not happening to you.

Here's the configuration on my Windows10

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T13:33:14-05:00)
Maven home: C:\apache-maven-3.5.4-bin\apache-maven-3.5.4\bin\..
Java version: 10.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-10.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

The error that I'm getting seems to be related to a plugin:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (test-testng) on project swagg
er-codegen: There are test failures.

I don't know if it's a configuration related issue, but the same happens on MacOS, so I'm not sure what the problem is.

Maybe there are other steps involved before building the project?

@sergio-alifano
i tried on a windows machine with java 10 and got your error, i think the java version you're using is no supported by maven-surefire-plugin. i switched to java 8 and worked fine for me.

Can you try with java 8? i think the surefire plugin needs update, but meantime i think you can work with java 8, in case it works for you.

@HugoMario thanks! Downgrading to Java 8 fixed the issue.

i'll continue figuring out how make it works with java 10, don't like the idea to be stuck in one java version.

For Ubuntu 18.04 with openjdk version "10.0.2", I resolved this issue by doing the following steps:

Installing openjdk 8:
sudo apt install openjdk-8-jdk

Use the openjdk 8 instead of the default one:
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/ mvn clean package and it will work!

@HugoMario have you found the issue with java 10 and is it fixed ?

I get the following errors when trying to build with Java-9:

Running TestSuite
java.lang.RuntimeException: java.io.IOException: Can not attach to current VM
    at mockit.internal.startup.AgentLoader.attachToRunningVM(AgentLoader.java:150)
    at mockit.internal.startup.AgentLoader.loadAgent(AgentLoader.java:60)
    at mockit.internal.startup.Startup.initializeIfPossible(Startup.java:200)
    at mockit.integration.testng.TestNGRunnerDecorator.onExecutionStart(TestNGRunnerDecorator.java:348)
    at org.testng.TestNG.runExecutionListeners(TestNG.java:1055)
    at org.testng.TestNG.run(TestNG.java:1002)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:132)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:193)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:94)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:147)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
Caused by: java.io.IOException: Can not attach to current VM
    at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.<init>(HotSpotVirtualMachine.java:75)
    at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:56)
    at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
    at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
    at mockit.internal.startup.AgentLoader.attachToRunningVM(AgentLoader.java:144)
    ... 12 more
[main] INFO io.swagge

https://bugs.eclipse.org/bugs/show_bug.cgi?id=534460#c10

It works with JDK 8 on WSL 1 (Ubuntu):
````

apt install -y openjdk-8-jdk

update-alternatives --config java

mvn clean package

````

It works with JDK 8 on WSL 1 (Ubuntu):

# apt install -y openjdk-8-jdk
# update-alternatives --config java
# mvn clean package

Thank you, I had tried installing Java 8 and changing the JAVA_HOME value but it was the update-alternatives --config java that got it working!

@rhysstubbs: FWITW, swagger has been superseded by OpenAPI:
https://github.com/OpenAPITools/openapi-generator
The OpenAPI generator doesn't have to be build like this and can be run from a docker image.

@strarsis really?

@HugoMario: From what I read and know and use, yes.

https://www.blazemeter.com/blog/whats-new-in-swagger-open-api3

OpenAPI 3 is the successor of the widely used OpenAPI/Swagger 2.0 format [...]

Hi guys, is ti bit late to comment?? lol ;) ... I had the same error and I was be able to fix with changing java version... some case swagger needs a maven version running over java 8 so, to fix please:

sudo yum install java-1.8.0-devel
sudo /usr/sbin/alternatives --config java
enter number of java 8 in prompted input
sudo /usr/sbin/alternatives --config javac
enter number of java 8 in prompted input

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] swagger-codegen-project ............................ SUCCESS [ 2.274 s]
[INFO] swagger-codegen (core library) ..................... SUCCESS [ 55.627 s]
[INFO] swagger-codegen (executable) ....................... SUCCESS [ 9.299 s]
[INFO] swagger-codegen (maven-plugin) ..................... SUCCESS [ 14.746 s]
[INFO] swagger-generator .................................. SUCCESS [ 14.082 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

check it this [https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-connect-prerq.html]

enjoy your quarantine

Was this page helpful?
0 / 5 - 0 ratings