I have a multi project gradle project (spring web), with the following layout:
springweb
| build.gradle
| settings.gradle
|_____ services
| build.gradle
| src/main/java
| src/main/resources
| src/test/java
| src/test/resources
| create-data.sql
|_____ web
| build.gradle
| src/main/java
| src/main/resources
| src/main/webapp
| src/test/java
| src/test/resources
When I try to execute the contents under src/test/resources (init.sql)
commandLine 'psql', '-h', 'localhost', '-d', 'junit', '--username', 'junit', '-f' , sourceSets['test'].output.resourcesDir.toString() + '/create-data.sql'
it failse because the resource is not available in the build directory:
/Users/me/dev/springweb/services/build/resources/test/create-data.sql: No such file or directory
below my root build.gradle:
ext {
springSecurityGroup = 'org.springframework.security'
springSecurityVersion = '3.1.4.RELEASE'
springGroup = 'org.springframework'
springVersion = '3.2.5.RELEASE'
hibernateGroup = 'org.hibernate'
hibernateVersion = '4.2.7.SP1'
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
sourceSets.all{
println output.classesDir
}
repositories {
mavenCentral()
}
}
and the 'services' build.gradle:
task createDb (type:Exec) {
println sourceSets['test'].output.resourcesDir.toString()
commandLine 'psql', '-h', 'localhost', '-d', 'junit', '--username', 'junit', '-f' ,'/Users/me/dev/sip/sip/sip04/src/main/resources/create-table.sql'
}
task fillDb (type:Exec, dependsOn: 'createDb') {
commandLine 'psql', '-h', 'localhost', '-d', 'junit', '--username', 'junit', '-f' , sourceSets['test'].output.resourcesDir.toString() + '/create-data.sql'
}
test.dependsOn fillDb
dependencies {
/* zipped */
}
/* Change context path (base url). otherwise defaults to name of project */
I execute it with gradle build:
gradle build
/Users/me/dev/springweb/services/build/classes/main
/Users/me/dev/springweb/services/build/classes/test
/Users/me/dev/springweb/web/build/classes/main
/Users/me/dev/springweb/web/build/classes/test
/Users/me/dev/springweb/services/build/resources/test
:services:compileJava UP-TO-DATE
:services:processResources UP-TO-DATE
:services:classes UP-TO-DATE
:services:jar UP-TO-DATE
:services:assemble UP-TO-DATE
:services:createDb
DROP TABLE
DROP SEQUENCE
zipped
:services:fillDb/Users/me/dev/springweb/services/build/resources/test/create-data.sql: No such file or directory
From the output I learn that the sourceSets are as I expect, but that the test resources are not copied. What is wrong?