Init.gradle

From NovaOrdis Knowledge Base
Revision as of 23:40, 7 February 2022 by Ovidiu (talk | contribs) (→‎Overview)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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|--init-script 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 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.