Skip to content

Instantly share code, notes, and snippets.

@marcingrzejszczak
Created July 8, 2019 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcingrzejszczak/20cda89b1c3605d3d9453549a49d37c4 to your computer and use it in GitHub Desktop.
Save marcingrzejszczak/20cda89b1c3605d3d9453549a49d37c4 to your computer and use it in GitHub Desktop.
How to replicate Gradle not loading extension modules

The problem

spring-cloud-contract-spec-groovy contains extension modules to the spring-cloud-contract-spec-java classes. The spring-cloud-contract-spec module includes both the groovy and the java modules together.

The whole project is being built and tested successfully apart from the integration with Gradle.

How to replicate

Clone the project, checkout the branch and build the whole thing without running tests:

$ git clone https://github.com/spring-cloud/spring-cloud-contract.git
$ cd spring-cloud-contract
$ git checkout rewriting_to_java
$ ./mvnw clean install -DskipTests -T 4 -Pfast

Now either you can run a build of the spring-cloud-contract-gradle project that will execute tests that will fail

$ cd spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin
$ ./gradlew clean build

or you can run a "normal" gradle project build. I guess using a standalone project will give you a "cleaner" classpath since in the plugin we use Nebula to setup classpath for tests.

$ cd samples/standalone/dsl/http-server/
$ /.gradlew clean build

The interesting classes

  • specs/spring-cloud-contract-spec-java/src/main/java/org/springframework/cloud/contract/spec/Contract.java - Java class that Groovy should extend with additional static and nonstatic methods

  • specs/spring-cloud-contract-spec-groovy/src/main/groovy/org/springframework/cloud/contract/spec/internal/ContractStaticExtension.groovy - extension module class

  • specs/spring-cloud-contract-spec-groovy/src/main/resources/META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule - extension module configuration

  • spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContractVerifierDslConverter.groovy - class that parses a contract DSL at runtime in order to generate tests and stubs (maybe class loaders are a problem there?)

  • spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin - the Gradle project setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment