pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 480 forks source link

java.lang.NoClassDefFoundError: com.amazonaws.services.s3.AmazonS3 #1063

Closed marcingrzejszczak closed 4 years ago

marcingrzejszczak commented 4 years ago

When trying to make Spring Cloud Contract work with 4.0.8 version of Pact JVM Consumer, I get the following exception

Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during instruction selection: java.lang.NoClassDefFoundError: com.amazonaws.services.s3.AmazonS3                                                       

java.lang.RuntimeException: java.lang.NoClassDefFoundError: com.amazonaws.services.s3.AmazonS3                                                                       
        at org.codehaus.groovy.control.CompilationUnit.convertUncaughtExceptionToCompilationError(CompilationUnit.java:1118)                                         
        at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1098)                                                           
        at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:640)                                                                    
        at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:618)                                                              
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:595)                                                                             
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:574)                                                                             
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                               
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                                                                             
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                                     
        at java.lang.reflect.Method.invoke(Method.java:498)                                                                                                          
        at org.codehaus.gmavenplus.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:213)   

When checking the dependencies I can see that I have a dependency on AmazonS3.

[INFO] +- au.com.dius:pact-jvm-consumer-java8:jar:4.0.8:compile
[INFO] |  \- au.com.dius:pact-jvm-consumer:jar:4.0.8:compile
[INFO] |     +- com.googlecode.java-diff-utils:diffutils:jar:1.3.0:compile
[INFO] |     +- dk.brics.automaton:automaton:jar:1.11-8:compile
[INFO] |     +- org.json:json:jar:20160212:compile
[INFO] |     +- io.netty:netty-handler:jar:4.1.48.Final:compile
[INFO] |     |  +- io.netty:netty-common:jar:4.1.48.Final:compile
[INFO] |     |  +- io.netty:netty-resolver:jar:4.1.48.Final:compile
[INFO] |     |  +- io.netty:netty-buffer:jar:4.1.48.Final:compile
[INFO] |     |  +- io.netty:netty-transport:jar:4.1.48.Final:compile
[INFO] |     |  \- io.netty:netty-codec:jar:4.1.48.Final:compile
[INFO] |     +- org.apache.httpcomponents:httpmime:jar:4.5.12:compile
[INFO] |     +- au.com.dius:pact-jvm-core-model:jar:4.0.8:compile
[INFO] |     |  +- com.github.zafarkhaja:java-semver:jar:0.9.0:compile
[INFO] |     |  +- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] |     |  +- com.github.mifmif:generex:jar:1.0.2:compile
[INFO] |     |  \- com.amazonaws:aws-java-sdk-s3:jar:1.11.587:runtime
[INFO] |     |     +- com.amazonaws:aws-java-sdk-kms:jar:1.11.587:runtime
[INFO] |     |     +- com.amazonaws:aws-java-sdk-core:jar:1.11.587:runtime
[INFO] |     |     |  +- software.amazon.ion:ion-java:jar:1.0.2:runtime
[INFO] |     |     |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.10.3:runtime
[INFO] |     |     |  \- joda-time:joda-time:jar:2.8.1:runtime
[INFO] |     |     \- com.amazonaws:jmespath-java:jar:1.11.587:runtime

Of course I don't use AmazonS3 at all. Can you mark this as optional or maybe I'm doing something wrong?

marcingrzejszczak commented 4 years ago

As a workaround I need to explicitly pass the AWS dependency.

uglyog commented 4 years ago

It shouldn't be loading that class if you are not using Amazon S3 as a source of pact files.

uglyog commented 4 years ago

Version 4.0.9 released.