Init.gradle: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
* https://docs.gradle.org/current/userguide/init_scripts.html | * https://docs.gradle.org/current/userguide/init_scripts.html | ||
=Internal= | =Internal= | ||
* [[Gradle_Concepts# | * [[Gradle_Concepts#init.gradle|Gradle Concepts]] | ||
=Overview= | |||
<code>init.gradle</code> is known as the Gradle init script. | |||
=Declaring an Init Script= | |||
There are several ways to declare an init script: | |||
* Specify a file on the command line. The command line option is <code>-I<code>|</code>--init-script</code> followed by the path to the script. The command line option can appear more than once, each time adding another init script. The build will fail if any of the files specified on the command line does not exist. | |||
* Put a file called <code>init.gradle</code> in <code>~/.gradle/</code>. | |||
* Put a file that ends with <code>.gradle</code> in <code>~/.gradle/init.d/</code>. | |||
* Put a file that ends with <code>.gradle</code> in <code>${GRADLE_HOME}/init.d/</code> directory, in the Gradle distribution. This allows you to package up a custom Gradle distribution containing some custom build logic and plugins. You can combine this with the Gradle wrapper as a way to make custom logic available to all builds where that instance is installed. | |||
If more than one init script is found they will all be executed, in the order specified above. Scripts in a given directory are executed in alphabetical order. This allows, for example, a tool to specify an init script on the command line and the user to put one in their home directory for defining the environment and both scripts will run when Gradle is executed. |
Latest revision as of 23:40, 7 February 2022
External
Internal
Overview
init.gradle
is known as the Gradle init script.
Declaring an Init Script
There are several ways to declare an init script:
- Specify a file on the command line. The command line option is
-I
followed by the path to the script. The command line option can appear more than once, each time adding another init script. The build will fail if any of the files specified on the command line does not exist.|
--init-script - Put a file called
init.gradle
in~/.gradle/
. - Put a file that ends with
.gradle
in~/.gradle/init.d/
. - Put a file that ends with
.gradle
in${GRADLE_HOME}/init.d/
directory, in the Gradle distribution. This allows you to package up a custom Gradle distribution containing some custom build logic and plugins. You can combine this with the Gradle wrapper as a way to make custom logic available to all builds where that instance is installed.
If more than one init script is found they will all be executed, in the order specified above. Scripts in a given directory are executed in alphabetical order. This allows, for example, a tool to specify an init script on the command line and the user to put one in their home directory for defining the environment and both scripts will run when Gradle is executed.