buildSrc is not a subproject of the root build, it is an “included build” (essentially its own root project). If you want to use spock in buildSrc, then it should have its own build.gradle with the appropriate repos/dependencies/configuration.
Ohhhh okay that makes more sense now - I didn’t realize I could add another build.gradle under buildSrc. I did just that and now it compiles, thank you! I’m having trouble running the test though:
root build.gradle (default setup when creating new project in IntelliJ):
plugins {
id 'groovy'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.spockframework:spock-core:2.0-groovy-2.5'
testImplementation 'org.codehaus.groovy:groovy-all:2.5.4'
}
test {
useJUnitPlatform()
}
buildSrc/src/test/groovy/SpockTest.groovy:
import spock.lang.Specification
class ExampleTest extends Specification{
def "should be a simple assertion"() {
expect:
1 == 1
}
}
When I try to run this test I get no errors but a message Test events were not received. After reading posts about similar issues, I tried modifying IntelliJ preferences to run tests using IntelliJ (instead of the default Gradle setting) and Invalidating Caches but I still get the same error. I’m on IntelliJ Community Edition 2019.3.3. Any thoughts here?
Also, would the command line equivalent be
./gradlew test --tests buildSrc/src/test/groovy/SpockTest.groovy
? When I try it, I get a BUILD SUCCESSFUL message but no indication of any tests running
buildSrc is a special project that builds as part of Gradle’s startup. The intent of buildSrc is to hold common/custom build logic for the project. Gradle must build the buildSrc project before it executes the project’s buildscripts.
If you run any task with --console=verbose you’ll see how Gradle runs a build in buildSrc first, including the buildSrc:test task.