Question

I am attempting to create my own task, that will create a package of all the artifacts generated during my multi-project build.

Currently what I do right is now just:

gradle build createPackage

Which gives output like the following:

:test-utility:compileJava UP-TO-DATE
:test-utility:processResources UP-TO-DATE
...
:test-utility:check UP-TO-DATE
:test-utility:build UP-TO-DATE
Creating Package...
Created.

BUILD SUCCESSFUL

Total time: 4.654 secs

With the createPackage task being:

task createPackage {    
    println "Creating Package..."
    println "Created."
}

However, I would like to simply it by running just one command, so what would the best way to do this and ensure the order stays maintained?

Ideally I would like to call build within the createPackage task or append to the build task with my task.

Was it helpful?

Solution

Ok reading between the lines there are a few things to clear up

1) Your printlns are being run in the configuration phase, not the execution phase. See http://www.gradle.org/docs/current/userguide/build_lifecycle.html for more info.

2) You do not have a single 'build' task. gradle build on the command line will run the 'build' task of each of your subprojects. Your package task would need to depend on all of them. Something like..

apply plugin: 'java'
evaluationDependsOnChildren()
task createPackage(type:Zip) {
   dependsOn subprojects*.build
}

3) You can be more declarative with gradle - just tell it what you want to package up and it will figure out what it needs to run. For example, you can say that you want to zip up all the jars from your subprojects.

apply plugin: 'java'    
evaluationDependsOnChildren()
task createPackage(type:Zip) {
   from subprojects*.jar
}

OTHER TIPS

There are plenty of ways. One suggestion is to modify build to depend on createPackage to make sure you can call just gradle build. Then you want to enhance your task and tell what are its inputs (probably those are outputs of some other tasks like jar). Gradle will add these tasks to execution when you run the build and can re-run them based on up-to-date status of each task. This is documented in userguide - http://www.gradle.org/docs/current/userguide/more_about_tasks.html#sec:up_to_date_checks and later in a chapter on custom tasks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top