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

Packaging 4.0.0 no class def found #1168

Closed
timja opened this issue May 13, 2019 · 26 comments
Closed

Packaging 4.0.0 no class def found #1168

timja opened this issue May 13, 2019 · 26 comments

Comments

@timja
Copy link

timja commented May 13, 2019

After trying to upgrade to 4.0.0 I was hit by a few Class not found exceptions:

ClassNotFoundException: io.restassured.path.xml.mapper.factory.JAXBObjectMapperFactory
ClassNotFoundException: io.restassured.path.json.mapper.factory.GsonObjectMapperFactory
java.lang.NoClassDefFoundError: io/restassured/path/json/mapper/factory/JohnzonObjectMapperFactory
cannot access TypeRef

From the wiki I should only need this dependency:

testCompile 'io.rest-assured:rest-assured:4.0.0'

That doesn't seem to be enough

I've made it work with:

  testCompile group: 'io.rest-assured', name: 'rest-assured', version: '4.0.0'
  testCompile group: 'io.rest-assured', name: 'rest-assured-common', version: '4.0.0'
  testCompile group: 'io.rest-assured', name: 'json-path', version: '4.0.0'
  testCompile group: 'io.rest-assured', name: 'xml-path', version: '4.0.0'

See:
hmcts/draft-store#293

@eszikk
Copy link

eszikk commented May 14, 2019

I have a same problem.

@johanhaleby
Copy link
Collaborator

Have you read the release notes? Some classes have been moved.

@johanhaleby
Copy link
Collaborator

johanhaleby commented May 16, 2019

Or are you not using these in your code? Are they runtime errors?

@johanhaleby
Copy link
Collaborator

TypeRef has also been moved, could that be the problem? It used to be io.restassured.mapper.TypeRef but has been moved to io.restassured.common.mapper.TypeRef

@timja
Copy link
Author

timja commented May 16, 2019

I'm not using them in my code at all, If I click through to rest assured classes they are missing the TypeRef and other classes.

It's a packaging issue, I saw the shade plugin is being used, something isn't setup right there

@timja
Copy link
Author

timja commented May 16, 2019

Also if you have a look at the PR I linked in the description the change it would show I'm not using the code directly 😉

@johanhaleby
Copy link
Collaborator

@timja Thanks for your reply. Yes it indeed feels like something is fishy. Haven't experienced this myself though in any of the projects I've upgraded to 4.0, I wonder why we have different experiences.

@johanhaleby
Copy link
Collaborator

@timja shade is also only used in the rest-assured-all module so I don't think it should impact the other modules

@johanhaleby
Copy link
Collaborator

@timja Also when I browse the rest-assured-common-4.0.0.jar I do see the TypeRef class

@johanhaleby
Copy link
Collaborator

Are you using the rest-assured-all module or OSGi or something? Are you sure you're not using both the new and the old version somehow? :)

@timja
Copy link
Author

timja commented May 16, 2019

No none of the above, the project is public and doesn't require anything special to build it.

./gradlew functionalTestClasses

is the quickest way to see the issue.

all changes are in this commit 66b0fd0be6258bce25ed142221d0e94f7f81bc49

https://github.com/hmcts/draft-store

$ rg rest-assured
build.gradle
201:  testCompile group: 'io.rest-assured', name: 'rest-assured', version: '4.0.0'
202:  testCompile group: 'io.rest-assured', name: 'rest-assured-common', version: '4.0.0'
203:  testCompile group: 'io.rest-assured', name: 'json-path', version: '4.0.0'
204:  testCompile group: 'io.rest-assured', name: 'xml-path', version: '4.0.0'

@timja
Copy link
Author

timja commented May 16, 2019

Also all the build failures can be viewed in the travis logs on the PR:
hmcts/draft-store#293

@johanhaleby
Copy link
Collaborator

Cannot seem to find the travis log, could you post the link here?

@timja
Copy link
Author

timja commented May 16, 2019

https://travis-ci.com/hmcts/draft-store/builds/111546866

uk.gov.hmcts.reform.draftstore.controllers.HandleUnknownExceptionTest > unhandledExceptionsShouldNotReturnExceptionDetailsToClient FAILED
    java.lang.NoClassDefFoundError: io/restassured/path/json/mapper/factory/JohnzonObjectMapperFactory
        at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
        at io.restassured.RestAssured.<clinit>(RestAssured.java:420)
        at uk.gov.hmcts.reform.draftstore.controllers.HandleUnknownExceptionTest.unhandledExceptionsShouldNotReturnExceptionDetailsToClient(HandleUnknownExceptionTest.java:54)
        Caused by:
        java.lang.ClassNotFoundException: io.restassured.path.json.mapper.factory.JohnzonObjectMapperFactory
            at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
            ... 3 more

Looks like that's the only build showing the packaging error, the first error was content being removed, the rest of the errors I experienced locally

@johanhaleby
Copy link
Collaborator

Might have found the issue:

+--- io.rest-assured:rest-assured:4.0.0
|    +--- org.codehaus.groovy:groovy:2.5.6
|    +--- org.codehaus.groovy:groovy-xml:2.5.6
|    |    \--- org.codehaus.groovy:groovy:2.5.6
|    +--- org.apache.httpcomponents:httpclient:4.5.3 -> 4.5.8
|    |    +--- org.apache.httpcomponents:httpcore:4.4.11
|    |    \--- commons-codec:commons-codec:1.11
|    +--- org.apache.httpcomponents:httpmime:4.5.3 -> 4.5.8
|    |    \--- org.apache.httpcomponents:httpclient:4.5.8 (*)
|    +--- org.hamcrest:hamcrest-core:2.1 -> 1.3
|    +--- org.hamcrest:hamcrest-library:2.1 -> 1.3
|    |    \--- org.hamcrest:hamcrest-core:1.3
|    +--- org.ccil.cowan.tagsoup:tagsoup:1.2.1
|    +--- io.rest-assured:json-path:4.0.0 -> 3.1.1
|    |    +--- org.codehaus.groovy:groovy-json:2.4.12 -> 2.5.6
|    |    |    \--- org.codehaus.groovy:groovy:2.5.6
|    |    +--- org.codehaus.groovy:groovy:2.4.12 -> 2.5.6
|    |    \--- io.rest-assured:rest-assured-common:3.1.1
|    |         +--- org.codehaus.groovy:groovy:2.4.12 -> 2.5.6
|    |         \--- org.apache.commons:commons-lang3:3.4 -> 3.8.1
|    \--- io.rest-assured:xml-path:4.0.0 -> 3.1.1
|         +--- org.codehaus.groovy:groovy-xml:2.4.12 -> 2.5.6 (*)
|         +--- org.codehaus.groovy:groovy:2.4.12 -> 2.5.6
|         +--- io.rest-assured:rest-assured-common:3.1.1 (*)
|         +--- org.apache.commons:commons-lang3:3.4 -> 3.8.1
|         +--- org.ccil.cowan.tagsoup:tagsoup:1.2.1
|         \--- javax.xml.bind:jaxb-api:2.2.12 -> 2.3.1
|              \--- javax.activation:javax.activation-api:1.2.0

For some reason xml-path depends on the old version. Need to investigate, but know I have to pick-up kids from Kindergarten :)

@geoffreywiseman
Copy link

I'm getting this instead, but I suspect it's related:
java.lang.NoClassDefFoundError: io/restassured/path/json/mapper/factory/JohnzonObjectMapperFactory

@timja
Copy link
Author

timja commented May 17, 2019

I also got that but forgot to include that in the description

@johanhaleby
Copy link
Collaborator

johanhaleby commented May 17, 2019

Are you all using Gradle? I'm not much of an Gradle expert but when running the following command in the draft-store project:

./gradlew dependencyInsight --dependency rest-assured --configuration testRuntimeClasspath

I get:

> Task :dependencyInsight
io.rest-assured:json-path:3.1.1 (selected by rule)
   variant "runtime" [
      org.gradle.status = release (not requested)
      Requested attributes not found in the selected variant:
         org.gradle.usage  = java-runtime
   ]

io.rest-assured:json-path:4.0.0 -> 3.1.1
\--- io.rest-assured:rest-assured:4.0.0
     \--- testRuntimeClasspath

io.rest-assured:rest-assured:4.0.0 (selected by rule)
   variant "default" [
      org.gradle.status = release (not requested)
      Requested attributes not found in the selected variant:
         org.gradle.usage  = java-runtime
   ]

io.rest-assured:rest-assured:4.0.0
\--- testRuntimeClasspath

io.rest-assured:rest-assured-common:3.1.1
   variant "runtime" [
      org.gradle.status = release (not requested)
      Requested attributes not found in the selected variant:
         org.gradle.usage  = java-runtime
   ]

io.rest-assured:rest-assured-common:3.1.1
+--- io.rest-assured:json-path:3.1.1
|    \--- io.rest-assured:rest-assured:4.0.0
|         \--- testRuntimeClasspath
\--- io.rest-assured:xml-path:3.1.1
     \--- io.rest-assured:rest-assured:4.0.0 (*)

io.rest-assured:xml-path:3.1.1 (selected by rule)
   variant "runtime" [
      org.gradle.status = release (not requested)
      Requested attributes not found in the selected variant:
         org.gradle.usage  = java-runtime
   ]

io.rest-assured:xml-path:4.0.0 -> 3.1.1
\--- io.rest-assured:rest-assured:4.0.0
     \--- testRuntimeClasspath

(*) - dependencies omitted (listed previously)

What does "io.rest-assured:json-path:3.1.1 (selected by rule)" mean? Which rule?

@johanhaleby
Copy link
Collaborator

I also found this answer on stackoverflow. He had a similar problem with elastic search and it turned out that spring-boot dependency management picked another version. Could it be the same thing here?

@johanhaleby
Copy link
Collaborator

johanhaleby commented May 17, 2019

The stackoverflow answer, that I linked to above, solved it by doing:

ext[elasticsearch.version] = '2.3.1'

And if I introduce this:

ext["rest-assured.version"] = '4.0.0'

it seem to pickup the correct version. Could you verify that it works? If so it's a gradle configuration issue and not a rest-assured issue.

@timja
Copy link
Author

timja commented May 17, 2019

Thanks @johanhaleby that's fixed

Apologies for not noticing that, and nice stack overflow answer

Thanks for spending your time looking at it, much appreciated.

Hopefully this issue is useful for anyone else who hits it

@timja timja closed this as completed May 17, 2019
@redstone1994
Copy link

I'm getting this instead, but I suspect it's related:
java.lang.NoClassDefFoundError: io/restassured/path/json/mapper/factory/JohnzonObjectMapperFactory

I have the same problem. Have you solved it?

@timja
Copy link
Author

timja commented May 27, 2019

Yes I was getting that too, if you're using spring and gradle then this will likely be the fix:
#1168 (comment)

@geoffreywiseman
Copy link

I have the same problem. Have you solved it?

Nope, I just rolled back to 3.x. Haven’t tried again yet. FWIW my issue was using Maven not Gradle.

@eliasnogueira
Copy link

eliasnogueira commented Jun 7, 2019

Guys!
Based on this link you can add a new dependency: rest-assured-all. It worked for me.
https://github.com/rest-assured/rest-assured/wiki/GettingStarted#java-9

Simply add the following dependency and keep the rest-assured dependency.

<dependency>
   <groupId>io.rest-assured</groupId>
   <artifactId>rest-assured-all</artifactId>
   <version>4.0.0</version>
</dependency>

My scenario: multi-project (module on IntelliJ) with a backend (spring boot) and a test project (using rest-assured) with JDK 12.

Spring Boot still using the 3.1.1 version of rest-assured on the last version (2.1.5.RELEASE).

@redstone1994
Copy link

Guys!
Based on this link you can add a new dependency: rest-assured-all. It worked for me.
https://github.com/rest-assured/rest-assured/wiki/GettingStarted#java-9

Simply add the following dependency and keep the rest-assured dependency.

<dependency>
   <groupId>io.rest-assured</groupId>
   <artifactId>rest-assured-all</artifactId>
   <version>4.0.0</version>
</dependency>

My scenario: multi-project (module on IntelliJ) with a backend (spring boot) and a test project (using rest-assured).

Spring Boot still using the 3.1.1 version of rest-assured on the last version (2.1.5.RELEASE).
But I use JDK1.8

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

6 participants