swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.38k stars 2.18k forks source link

build fails in tests (dynamically loading classes) due to missing dependencies in swagger-models #1941

Closed DavidBiesack closed 7 years ago

DavidBiesack commented 8 years ago

clone swagger-core repo and build

mvn -N mvn install

I get a build failure:

Tests run: 288, Failures: 1, Errors: 0, Skipped: 55, Time elapsed: 4.066 sec <<< FAILURE! - in TestSuite
setup(io.swagger.PojosTest)  Time elapsed: 1.189 sec  <<< FAILURE!
java.lang.NoClassDefFoundError: Lorg/joda/time/DateTime;
    at io.swagger.PojosTest.setup(PojosTest.java:62)
Caused by: java.lang.ClassNotFoundException: org.joda.time.DateTime
    at io.swagger.PojosTest.setup(PojosTest.java:62)

Results :

Failed tests: 
io.swagger.PojosTest.setup(io.swagger.PojosTest)
  Run 1: PojosTest.setup:62 ? NoClassDefFound Lorg/joda/time/DateTime;
  Run 2: PASS
  Run 3: PASS

Tests run: 259, Failures: 1, Errors: 0, Skipped: 26

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] swagger-project ................................... SUCCESS [  2.382 s]
[INFO] swagger-annotations ............................... SUCCESS [  7.357 s]
[INFO] swagger-models .................................... FAILURE [  5.921 s]

the swagger-models.

I can add joda-time to modules/swagger-models/pom.xml but then I get another failure:

Tests run: 288, Failures: 1, Errors: 0, Skipped: 55, Time elapsed: 4.422 sec <<< FAILURE! - in TestSuite
setup(io.swagger.PojosTest)  Time elapsed: 1.2 sec  <<< FAILURE!
java.lang.NoClassDefFoundError: Lorg/apache/commons/lang3/tuple/Pair;
    at io.swagger.PojosTest.setup(PojosTest.java:62)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.tuple.Pair
    at io.swagger.PojosTest.setup(PojosTest.java:62)

adding apache-commons to swagger-models/pom.xml

after adding that, the same dynamic class load ( io.swagger.PojosTest.setup ) fails because jackson.databind is missing. adding that dependency resolves the build and I get SUCCESS

I'll submit a PR for this.

webron commented 8 years ago

@DavidBiesack - thank you for reporting this.

We've spent quite some time now trying to reproduce the issue, but were unable to. That included completely deleting .m2, checking on multiple machines and environments.

Can you share which version of Java and Maven you used when you ran the build?

DavidBiesack commented 8 years ago
$ mvn --v : 
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T12:37:52-05:00)
Maven home: /u/sasdjb/java/apache-maven-3.2.1
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre

(this is on Linux, Xubuntu 16.04)

We have Artifactory running and my mvn settings.xml points to that (it mirrors Maven central)

I upgraded to Maven 3.3.9 and moved my ~/.m2/settings.xml (to bypass Artifactory) and I get a clean build.

I then reverted everything (switched my branch back to master, Maven back to 3.2.1, and restored ~/.m2/settings.xml) and did a mvn clean test and .... it worked, all SUCCESS.

I'm not sure of the cause or what changed to allow it to pass.

Still, it is not clear where those dependencies would come from since they are not explicit. if I do

    $ mvn dependency:copy-dependencies

I get the following in swagger-models:

  total used in directory 3940 available 145857344
  drwxrwxr-x 2 sasdjb sasdjb    4096 Sep 22 18:10 .
  drwxrwxr-x 9 sasdjb sasdjb    4096 Sep 22 18:10 ..
  -rw-rw-r-- 1 sasdjb sasdjb   43581 Sep 22 18:10 asm-3.3.1.jar
  -rw-rw-r-- 1 sasdjb sasdjb  281694 Sep 22 18:10 bsh-2.0b4.jar
  -rw-rw-r-- 1 sasdjb sasdjb   76643 Sep 22 18:10 hamcrest-core-1.1.jar
  -rw-rw-r-- 1 sasdjb sasdjb   38596 Sep 22 18:10 jackson-annotations-2.4.5.jar
  -rw-rw-r-- 1 sasdjb sasdjb  750581 Sep 22 18:10 javassist-3.20.0-GA.jar
  -rw-rw-r-- 1 sasdjb sasdjb   63504 Sep 22 18:10 jcommander-1.48.jar
  -rw-rw-r-- 1 sasdjb sasdjb 1172979 Sep 22 18:10 mockito-core-1.10.19.jar
  -rw-rw-r-- 1 sasdjb sasdjb   41755 Sep 22 18:10 objenesis-2.1.jar
  -rw-rw-r-- 1 sasdjb sasdjb  259750 Sep 22 18:10 openpojo-0.8.0.jar
  -rw-rw-r-- 1 sasdjb sasdjb   99172 Sep 22 18:10 powermock-api-mockito-1.6.4.jar
  -rw-rw-r-- 1 sasdjb sasdjb   19460 Sep 22 18:10 powermock-api-support-1.6.4.jar
  -rw-rw-r-- 1 sasdjb sasdjb  104918 Sep 22 18:10 powermock-core-1.6.4.jar
  -rw-rw-r-- 1 sasdjb sasdjb   12077 Sep 22 18:10 powermock-module-testng-1.6.4.jar
  -rw-rw-r-- 1 sasdjb sasdjb    4844 Sep 22 18:10 powermock-module-testng-common-1.6.4.jar
  -rw-rw-r-- 1 sasdjb sasdjb   47279 Sep 22 18:10 powermock-reflect-1.6.4.jar
  -rw-rw-r-- 1 sasdjb sasdjb   25689 Sep 22 18:10 slf4j-api-1.6.3.jar
  -rw-rw-r-- 1 sasdjb sasdjb   20418 Sep 22 18:10 swagger-annotations-1.5.11-SNAPSHOT.jar
  -rw-rw-r-- 1 sasdjb sasdjb  865813 Sep 22 18:10 testng-6.9.4.jar

(no joda-time, no apache-commons, no jackson-databind)

webron commented 8 years ago

Yes, @DavidBiesack - that puzzled me too as I was unable to find the dependencies directly as well. That said, it could be one of the many many wonders of Maven.

Going back to the root of the project, and running mvn dependency:tree | grep joda, you get the following output:

[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.5:compile
[INFO] +- joda-time:joda-time:jar:2.2:test
[INFO] +- org.joda:joda-convert:jar:1.2:test
[INFO] |  +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.5:compile
[INFO] |  |  \- joda-time:joda-time:jar:2.2:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.5:compile
[INFO] |  |  |  \- joda-time:joda-time:jar:2.2:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.5:compile
[INFO] +- joda-time:joda-time:jar:2.2:test
[INFO] +- org.joda:joda-convert:jar:1.2:test
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.5:compile
[INFO] |  |  |  \- joda-time:joda-time:jar:2.2:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.5:compile
[INFO] |  |  |  \- joda-time:joda-time:jar:2.2:compile
[INFO] |  +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.5:compile
[INFO] |  |  \- joda-time:joda-time:jar:2.2:compile

I'm not an expert when it comes to how Maven manages test dependencies, but that could hint at something (and you see that the joda projects are scoped as test).

More commonly, similar issues I've seen in the past were resolved by upgrading to the latest version of Maven (and both my colleague and I tested with 3.3.9). I can't really explain why reverting the changes didn't break things back again.

While I appreciate the PR, I'd rather avoid adding more explicit dependencies if those are, well, not explicitly required. You can see how dependency management be hell, and the more we add, the harder it is to manage.

DavidBiesack commented 8 years ago

understood. This issue will be retained, so if someone else encounters the problem, there is a record and we can revisit. Thanks for looking.

"when you hear this... you know you'r in a software project"