Search code examples
gradlespring-cloud-contract

Changing from the default "test" directory for Spring Contract's contracts and base class tests


I have tried changing the default test directory name for base test classes as follows:

Old:

bignibou-server/src/test/java/com/bignibou/signup

New:

bignibou-server/src/contracts/java/com/bignibou/signup

Here is the directory where my contracts live:

New:

bignibou-server/src/contracts/resources/contracts/signup

Here is my gradle configuration:

contracts {
    packageWithBaseClasses = 'com.bignibou'
    baseClassMappings {
        baseClassMapping(".*signup*.", "com.bignibou.signup.SignupBase")
    }
}

I use the same gradle configuration both for contracts tests & integration tests. See:

sourceSets {

    integrationTest {
        java.srcDirs = ['src/it/java', 'src/contracts/java']
        resources.srcDirs = ['src/it/resources', 'src/contracts/resources']
        compileClasspath = sourceSets.main.output + configurations.testRuntime
        runtimeClasspath = output + compileClasspath
    }
}

However, since I moved my base class tests & contracts from the test directory, the contracts tests are nor run...

edit:

After searching the documentation, I found the contractsDslDir property that can be used as follows:

contracts {
    packageWithBaseClasses = 'com.bignibou'
    contractsDslDir = new File("${project.rootDir}/src/contracts/resources/contracts")
    baseClassMappings {
        baseClassMapping(".*signup*.", "com.bignibou.signup.SignupBase")
    }
}

However, the tests are still not run... What else I am missing?

Here is how I try to run the tests:

./gradlew clean check

edit 2:

I was able to get Spring Cloud Contract to find my contract using the following value for contractsDslDir:

contractsDslDir = new File("./src/contracts/resources/contracts")

Now the issue is that my test won't find the test base:

> Task :bignibou-server:compileTestJava FAILED
/Users/julien/Documents/projects/bignibou/bignibou-server/build/generated-test-sources/contracts/com/bignibou/SignupTest.java:3: error: package com.bignibou.signup does not exist
import com.bignibou.signup.SignupBase;
                          ^
/Users/julien/Documents/projects/bignibou/bignibou-server/build/generated-test-sources/contracts/com/bignibou/SignupTest.java:20: error: cannot find symbol
public class SignupTest extends SignupBase {
                                ^
  symbol: class SignupBase
2 errors

FAILURE: Build failed with an exception.

edit 3: It is odd: Spring Cloud Contracts still seems bound to the test gradle task (as opposed to my custom integrationTest one)...

When I run ./gradlew clean integrationTest the contracts are not even searched... However when I run ./gradlew clean test I get the above error indicating that Spring Cloud Contract is looking for a base class but not finding one.

How can I tell Spring Cloud Contract to bind to my custom integrationTest gradle task?


Solution

  • It's not supported at the moment. Feel free to find the issue or create a new one if you can't find it