Search code examples
spring-cloud-contract

why compileTestGroovy fails in a Gradle, Kotlin, Spring Boot app using Spring Cloud Contract


Spring Cloud Contract Gradle Plugin (2.0.2.RELEASE)

My Kotlin project, a Spring Boot 2.0.5.RELEASE application with a Groovy contract file under src/test/resources/contracts and Base test class being com.mycompany.practice.base.producer.PracticeMessagingBase successfully produces a ContractVerifierTest and opening that file suggests that IntelliJ is happy with the file but running the ./gradlew clean build fails on compileTestGroovy

> Task :compileTestGroovy FAILED
file or directory '/Users/abc/Documents/code/dev/practice-service/src/test/groovy', not found
file or directory '/Users/abc/Documents/code/dev/practice-service/src/test/groovy', not found
Task ':compileTestGroovy' is not up-to-date because:
  Task has failed previously.
Excluding []
file or directory '/Users/abc/Documents/code/dev/practice-service/src/test/groovy', not found
Starting process 'Gradle Worker Daemon 1'. Working directory: /Users/abc/.gradle/workers Command: /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/java -Djava.security.manager=worker.org.gradle.process.internal.worker.child.BootstrapSecurityManager -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -cp /Users/abc/.gradle/caches/4.7/workerMain/gradle-worker.jar worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Worker Daemon 1'
Successfully started process 'Gradle Worker Daemon 1'
Started Gradle worker daemon (0.458 secs) with fork options DaemonForkOptions{executable=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/java, minHeapSize=null, maxHeapSize=null, jvmArgs=[], classpath=[/Users/abc/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-ant/2.4.15/2faf2c49f25ce9868b2eed1aa7dc1ecd98d33353/groovy-ant-2.4.15.jar, /Users/abc/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-groovydoc/2.4.15/7bace00f98542934e10c069d067df6e77e17f6cd/groovy-groovydoc-2.4.15.jar, /Users/abc/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-templates/2.4.15/b5cbe971f2950452c1d431ea0135dd8de2d5f58e/groovy-templates-2.4.15.jar, /Users/abc/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-xml/2.4.15/40865f59469e6b0808c9c304bd17038997220c72/groovy-xml-2.4.15.jar, /Users/abc/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.4.15/74b7e0b99526c569e3a59cb84dbcc6204d601ee6/groovy-2.4.15.jar, /Users/abc/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant-junit/1.9.4/b063757dacaa716b643c2f9270e469183636ff11/ant-junit-1.9.4.jar, /Users/abc/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant/1.9.4/6d473e8653d952045f550f4ef225a9591b79094a/ant-1.9.4.jar, /Users/abc/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant-launcher/1.9.4/334b62cb4be0432769679e8b94e83f8fd5ed395c/ant-launcher-1.9.4.jar, /Users/abc/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant-antlr/1.9.4/4cf30025981dc2344324a0ef0e40063c3ef08f0a/ant-antlr-1.9.4.jar, /Users/abc/.gradle/wrapper/dists/gradle-4.7-all/4cret0dgl5o3b21weaoncl7ys/gradle-4.7/lib/ant-1.9.9.jar, /Users/abc/.gradle/wrapper/dists/gradle-4.7-all/4cret0dgl5o3b21weaoncl7ys/gradle-4.7/lib/ant-launcher-1.9.9.jar], keepAliveMode=SESSION}.
Compiling with JDK Java compiler API.
/Users/abc/Documents/code/dev/practice-service/build/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java:3: error: package com.mycompany.practice.base.producer does not exist
import com.mycompany.practice.base.producer.PracticeMessagingBase;
                                               ^
/Users/abc/Documents/code/dev/practice-service/build/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java:16: error: cannot find symbol
public class ContractVerifierTest extends PracticeMessagingBase {
                                          ^
  symbol: class PracticeMessagingBase
/Users/abc/Documents/code/dev/practice-service/build/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java:24: error: cannot find symbol
                        process();
                        ^
  symbol:   method process()
  location: class ContractVerifierTest
3 errors
startup failed:
Compilation failed; see the compiler error output for details.

1 error

:compileTestGroovy (Thread[Task worker for ':',5,main]) completed. Took 1.807 secs.

Could I be doing something fundamentally wrong?


Solution

  • If you take a look at the task that is failing - it's compileTestGroovy. Since Groovy can compile java, it's trying to compile the base class. However it can't really compile the base class since it can't access the Kotlin's base class. Just set compileTestGroovy.enabled = false in build.gradle and everything will work fine