u1234
(tulsoba)
May 6, 2013, 10:37am
1
Using gradle 1.5. I have a multi project. Two of the projects build an ear file. A third project copies the two ear files and zips them together:
configurations {
myConf
}
dependencies {
myConf project(path: ':FirstEarProject:ear', configuration: 'earConf')
myConf project(path: ':SecondEarProject:ear', configuration: 'earConf')
}
task myCopy << {
copy {
from configurations.myConf
into file("$buildDir/staging")
}
}
task myZip(dependsOn: 'myCopy ', type: Zip){
from "$buildDir/staging"
}
when I run : “gradle clean install myZip” a zip file is created but it only contains one of the ear files, the FirstEarProject.ear. The directory:
“$buildDir/staging”
also only contains: FirstEarProject.ear. Why does it skip the SecondEarProject.ear file when copying?
I have tried to create a second configuration “myConfOther” and a second copy task and then it works:
configurations {
myConfOther
}
dependencies {
myConf project(path: ':FirstEarProject:ear', configuration: 'earConf')
myConfOther project(path: ':SecondEarProject:ear', configuration: 'earConf')
}
task myCopy << {
copy {
from configurations.myConf
into file("$buildDir/staging")
}
copy {
from configurations.myConfOther
into file("$buildDir/staging")
}
}
task myZip(dependsOn: 'myCopy ', type: Zip){
from "$buildDir/staging"
}
But it could be nice not having to create a conf for each file to copy.
The ‘myCopy’ task is missing a ‘dependsOn’. It’s much better to declare it as a task of type ‘Copy’:
task myCopy(type: Copy) {
from configurations.myConf
into "$buildDir/staging"
}
Among other things, this will give you task autowiring (no need to manually declare task dependencies) and up-to-date checking.
Unless you absolutely need a staging directory, pulling everything directly into the Zip is even better. You can still have an ‘explodedZip’ task, but the ‘myZip’ task shouldn’t depend on it.
u1234
(tulsoba)
May 6, 2013, 11:08am
3
I now have:
configurations {
myConf
}
dependencies {
myConf project(path: ':FirstEarProject:ear', configuration: 'earConf')
myConf project(path: ':SecondEarProject:ear', configuration: 'earConf')
}
task myCopy(type: Copy) {
from configurations.myConf
into "$buildDir/staging"
}
task myZip(dependsOn: 'myCopy ', type: Zip){
from "$buildDir/staging"
}
but the staging dir/zip file still only contains:
FirstEarProject.ear
I can’t spot any other problem with this build script (assuming ‘:SecondEarProject:ear’ is really the project path). Might be a problem with one of the other build scripts then. Without a way to reproduce it’s hard to say.
u1234
(tulsoba)
May 6, 2013, 11:19am
5
If I comment out FirstEarProject.ear :
configurations {
myConf
}
dependencies {
//myConf project(path: ':FirstEarProject:ear', configuration: 'earConf')
myConf project(path: ':SecondEarProject:ear', configuration: 'earConf')
}
task myCopy(type: Copy) {
from configurations.myConf
into "$buildDir/staging"
}
task myZip(dependsOn: 'myCopy ', type: Zip){
from "$buildDir/staging"
}
the zipfile contains the SecondEarProject.ear. So it works when either one of the files are copied but not both. Strange.