Gradle offers multiple ways to skip the execution of a task.
The -D option of the gradle command has the same effect as the -D option of the java command. This way you can set system properties of the JVM that runs Gradle. You can add one ore more skip properties to any existing task. If the corresponding system property is set to any value/footnoteThe statement -Dprop sets the property to empty string, thus you don’t need to type more to skip a task. except false (case does not matter), the actions of the task don’t get executed. But often you don’t even need to set the skip properties. If you set a system property according to the pattern skip.taskname , the actions of this task don’t get executed.
If you want tasks to be skipped, that depends on a skipped task, you have to declare this explicitly via the skip properties
If the rules for skipping a task can’t be expressed with a simple property, you can use the StopExecutionException1 . If this exception is thrown by an action, the further execution of this action as well as the execution of any following action of this task is skipped. The build continues with executing the next task.
This feature is helpful if you work with tasks provided by Gradle. It allows you to add conditional execution of the built-in actions of such a task.
You might be wondering why there is neither an import for the StopExecutionException nor do we access it via its fully qualified name. The reason is, that Gradle adds a set of default imports to your script. These imports are customizable (see Appendix ??).
Every task has also a enabled flag which defaults to true. Setting it to false prevents the execution of any of the tasks actions.
All available command line options are listed in Appendix C. You can also print them to your console with gradle -h.
We want to look at the console output options in more detail.
| Option | Meaning |
| neither q nor d | Gradle and Ant will print out info log messages. |
| q | Only errors are printed to the console. |
| d | Gradle and Ant will print out info and debug log messages. |
| Option | Meaning |
| neither s nor f | No stacktraces are printed to the console in case of a build error (e.g. a compile error). Only in case of internal exceptions will stacktraces be printed. If the loglevel option d is choosen, truncated stacktraces are always printed. |
| s | Truncated stacktraces are printed. We recommend this over full stacktraces. Groovy full stacktraces are extremely verbose (Due to the underlying dynamic invocation mechanisms. Yet they usually do not contain relevant information for what has gone wrong in your code.) |
| f | The full stacktraces are printed out. |
There is a common situation, that multiple tasks depend on the existence of a directory. Of course you can deal with this by adding a mkdir to the beginning of those tasks. But this is kind of bloated. There is a better solution (works only if the tasks that need the directory have a dependsOn relationship):
But Gradle offers you also Directory Tasks to deal with this.
A Directory Task is a simple task which name is a relative path to the project dir2 . During the execution phase the directory corresponding to this path gets created if it does not exist yet. Another interesting thing to note in this example, is that you can also pass tasks objects to the dependsOn declaration of a task.
Gradle offers a variety of ways to add properties to your build. With the -D command line option you can pass a system property to the JVM which runs Gradle.
There is also the possibility to directly add properties to your project objects. You can place a gradle.properties file either in the Gradle user home dir (defaults to USER_HOME/.gradle) or in your project dir. For multiproject builds you can place gradle.properties files in any subproject. The properties of the gradle.properties can be accessed via the project object. The properties file in the the user’s home directory has precedence over property files in the project directories.
You can also add properties directly to your project object via the -P command line option. For more exotic use cases you can even pass properties directly to the project object via system and environment properties. For example if you run a build on a continuous integration server where you have no admin rights for the machine. Your build script needs properties which values should not be seen by others. Therefore you can’t use the -P option. In this case you can add an environment property in the project adminstration section (invisible to normal users).3 If the environment property follows the pattern ORG_GRADLE_PROJECT_yourProperty=somevalue, yourProperty is added to your project object. If in the future CI servers support Gradle directly, they might start Gradle via its main method. Therefore we already support the same mechanism for system properties. The only difference is the prefix, which is org.gradle.project..
With the gradle.properties files you can also set system properties. If a property in such a file has the prefix systemProp. the property and its value are added to the system properties (without the prefix).
Setting a proxy for web access (for example for downloading dependencies) is easy. Gradle does not need to provide special functionality for this. The JVM can be instructed to go via proxy by setting certain system properties. You could set this system properties directly in your build script with System.properties[’proxy.proxyUser’] = ’userid’. An arguably nicer way is shown in section 4.4. Your gradle.properties file could look like this:
We could not find a good overview for all possible proxy settings. The best we can offer are the constants in a file from the ant project. Here a link to the svn view. If anyone knows a better overview please let us know via the mailing list.