Reputation: 75
My following project structure looks like:
.
├── build.gradle
├── out.txt
├── Server
│ ├── build.gradle
│ ├── plugins
│ │ └── TestPlugin-0.1.0.zip
│ └── src
├── pluginApi
│ ├── build
│ ├── build.gradle
│ └── src
├── plugins
│ └── testPlugin
│ ├── build
│ │ ├── libs
│ │ │ └── TestPlugin-0.1.0.zip
│ ├── build.gradle
│ └── src
└── settings.gradle
Now I want to create a gradle task in the main build.gradle which should do something like that:
I managed to write a simple task like this:
task compilePluginsAndCopy() {
delete 'Server/plugins'
mkdir 'Server/plugins'
subprojects.each { p ->
if (p.path.contains("plugins/")) {
p.createZip
doLast {
copy {
from p.path.substring(1) + '/build/libs'
into 'Server/plugins'
}
}
}
}
}
When I now run this task the zip file doesn't get created and nothing gets deleted. However when I run the "createZip" task on one of the subprojects the task compilePluginsAndCopy gets executed.
Could somebody help me, please?
Upvotes: 6
Views: 6490
Reputation: 23647
Your task definitions should look like this:
task compilePluginsAndCopy() << {
...
}
note the <<
.
<<
is short hand for doLast
. The non short hand way to do this would be:
task compilePluginsAndCopy() {
doLast {
...
}
}
If your code is not contained in a doLast block, it is executed in the configuration phase, which is what you're seeing when you run a different task.
Upvotes: 4