I have java project with 2 subprojects. With structure like this
- project_root
|- client
|- src
|- build.gradle
|- server
|- src
|- build.gradle
|- build.gradle
All I need is to create 'deploy' task in root buiild.gradle with next actions:
- clean all subprojects
- clean 'target' folder
- make jars for all subprojects
- copy jars from all subprojects to folder 'target' in root
- make an archive of the target folder.
This is how I try to do this
root build.gradle:
allprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
}
task cleanTarget(type: Delete) {
delete "target"
delete "target.zip"
}
task cleanAll() {
dependsOn cleanTarget
dependsOn clean
dependsOn subprojects.clean
}
task jarChilds() {
dependsOn subprojects.jar
}
task copyFiles(type: Copy) {
copy {
from("client/build/libs/")
into project.file('target')
}
copy {
from("server/build/libs/")
into project.file('target')
}
}
task zipApp(type: Zip) {
from 'target/'
include '*'
include '*/*'
archiveName 'target.zip'
destinationDir(project.rootDir)
}
task deploy{
dependsOn cleanAll
dependsOn jarChilds
dependsOn copyFiles
dependsOn zipApp
jarChilds.shouldRunAfter cleanAll
copyFiles.shouldRunAfter jarChilds
zipApp.shouldRunAfter copyFiles
}
Every task runs properly if I manually run it, but if I run 'deploy' folder 'target' didn't create. Here is log output:
Executing task 'deploy'...
> Task :clean
> Task :cleanTarget
> Task :client:clean
> Task :server:clean
> Task :cleanAll
> Task :client:compileKotlin
> Task :client:compileJava
> Task :client:processResources
> Task :client:classes
> Task :client:inspectClassesForKotlinIC
> Task :client:jar
Client jar done
> Task :server:compileKotlin
> Task :server:compileJava
> Task :server:processResources
> Task :server:classes
> Task :server:inspectClassesForKotlinIC
> Task :server:jar
Server jar done
> Task :jarChilds
> Task :copyFiles NO-SOURCE
> Task :zipApp NO-SOURCE
> Task :deploy
BUILD SUCCESSFUL in 3s
14 actionable tasks: 14 executed
12:39:15: Task execution finished 'deploy'.
I see that error "NO-SOURCE", but folders 'client/build/libs' and 'server/build/libs' exist and contain jars. I can be sure because the manual running task 'copyFiles' create folder 'target' and copy all files. The only possible option that I see is 'copyFiles' task running before 'jarChilds'. But I don't understand why. What am I missing, why is it not working?
P/S/ Sorry for my bad English