What is the code version of './gradlew build -x :subproj1:build -x :subproj2:build -x test'


I want to add a new task to my build.gradle file which does the equivalent of:

‘./gradlew build -x :subproj1:build -x :subproj2:build -x test’

I want to run it like:

‘./gradlew miniBuild’

Can someone please help me write the equivalent code for the task? The goal is to speed up developer build turnaround times.

Thanks, Tom

There might be other ways to get what you want without changing your build script.

Take a look at the tasks available (and their dependencies) by running:

./gradlew tasks --all

You can also abbreviate task names in a lot of cases to save on typing (http://www.gradle.org/docs/current/userguide/tutorial_gradle_command_line.html#N1080F).

It looks like you want to only build the root project. Just like you can refer to the subproject tasks with ‘subproject:task’, you can refer to the root project by its name (’:’, just a colon). So if you want to just build the root project, you can do:

./gradlew :build

This doesn’t do exactly what you want because we’re still running tests.

With a regular Java project, build is nothing more than assemble and check. assemble is just jar and check is just test.

So I think you can get what you want with:

./gradlew :assemble

If you have something else under ‘check’ (e.g., checkstyle) that you also want to run, but still skip test, you can do this (in build.gradle):

// in root project
 task miniBuild(dependsOn: [ ':assemble', ':checkstyle' ])

and use it as you initially wanted:

./gradlew miniBuild

If you’re going to add a custom task, it would be helpful to include a description and put it under a group, so developers can find it easily via ‘tasks’. e.g.:

// in root project
 task miniBuild(group: "Quick", dependsOn: [ ':assemble', ':checkstyle' ]) {
   description = "Runs a quick build"