class PropertiesPlugin extends java.lang.Object
This is the main class for the properties plugin. When the properties
plugin is applied to a project, it uses the values of the
environmentName and gradleUserName properties to reload all
the project properties in the following order:
ORG_GRADLE_PROJECT_.
org.gradle.project..
When the plugin is applied to a Settings object, it uses the
environmentName and gradleUserName properties to reload all
the settings properties in the following order:
*
ORG_GRADLE_PROJECT_.
org.gradle.project..
As mentioned, this plugin looks for the gradle-${environmentName}.properties
file in the project directory for projects, or the directory with
settings.gradle if the plugin is applied to a Settings object. You can
change this behavior by specifying a value for the environmentFileDir
property. It is strongly recommended to use a subdirectory of the project
or settings directory when using this option. This property only effects
where the environment specific files are located, it does not change where
the plugin looks for the other files, such as the user files or default
gradle files.
environmentFileDir, environmentName, and
gradleUserName are the properties that this plugin use by default to
get the location of the environment files and the names of the environment
and gradle user to use. If you don't like these names, or if there is a
clash with properties you already use in your build, you can configure the
properties the plugin will use. You can tell the plugin what property to
use for the environment file directory by setting a value for the
propertiesPluginEnvironmentFileDirProperty property. You can tell
the plugin what property to use for the name of the environment by setting
the propertiesPluginEnvironmentNameProperty, and you can tell the
plugin what property to use to set the user name by setting a value for the
propertiesPluginGradleUserNameProperty property. Those properties
have to be set before this plugin is applied. That means you can put them in
the standard property file locations supported by Gradle itself, in
environment variables, system properties, -P options or in the build.gradle
file itself before applying this plugin.
The last thing to set a property wins. All files are optional unless an environment or user is specified, in which case the file belonging to the specified environment or user must exist. If an environment file directory is specified, that directory must exist, be a directory, and be readable.
As properties are set, they are also placed in a filterTokens property. the filterTokens property is a map of tokens that can be used when doing a filtered file copy. There will be a token for each property defined by one of the listed methods. The name of each token will be the name of the property from the properties file, after converting the camel case property name to dot notation. For example, if you have a myPropertyName property in the file, the plugin will create a my.property.name filter token, whose value is the property's value. The original camel case name will also be added as token.
By default, this plugin fails the build if you specify an environment, but
no file exists for that environment. You can use the
propertiesPluginIgnoreMissingEnvFile property to override this
behavior.
Finally, the properties plugin also adds some properties to every task in your build:
requiredProperty and requiredProperties can be used to
define what properties must be present for that task to work. Required
properties will be checked after configuration is complete, but before any
tasks are executed.
recommendedProperty and recommendedProperties can be used
to define properties that the task can work without, but it (or the deployed
application) will use a default value for the property. The value of this
property is that we can prompt new developers to either provide a property,
or make sure default config files are set up correctly.
Special thanks to Hans Dockter at Gradleware for showing me how to attach to the right place in the Gradle build lifecycle.
| Type | Name and description |
|---|---|
java.lang.Object |
logger |
| Type Params | Return Type | Name and description |
|---|---|---|
|
void |
apply(org.gradle.api.plugins.PluginAware pluginAware)This method is called then the properties-plugin is applied. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
This method is called then the properties-plugin is applied. It can
be applied to both Project and Settings objects.
the - object to which this plugin should be applied. Currently,
this must be either a Project or Settings object.