Gradle Local Properties Plugin
A Gradle plugin that lets a local gradle.local.properties file override the values in gradle.properties.
Developers often need different property values on their own machine, such as a local repository URL, a feature flag or a credential.
Editing the shared gradle.properties risks committing those values by accident.
With this plugin you keep the overrides in gradle.local.properties and leave the shared file untouched.
-
Properties in
gradle.local.propertiesreplace the project properties of the same name. -
Properties that don’t exist yet are added.
-
A warning is logged whenever the file is found and contains properties, so overrides are never silent.
Build Configuration
Apply the plugin to the project that contains (or should read) gradle.local.properties.
Groovy DSL (build.gradle)
plugins {
id 'org.infosmid.plugins.local-properties' version '1.0.3'
}
Kotlin DSL (build.gradle.kts)
plugins {
id("org.infosmid.plugins.local-properties") version "1.0.3"
}
Version Catalog (gradle/libs.versions.toml)
Declare the plugin in the catalog:
[versions]
local-properties = "1.0.3"
[plugins]
infosmid-local-properties = { id = "org.infosmid.plugins.local-properties", version.ref = "local-properties" }
Then reference it through the generated libs accessor.
build.gradle)plugins {
alias(libs.plugins.infosmid.local.properties)
}
build.gradle.kts)plugins {
alias(libs.plugins.infosmid.local.properties)
}
The plugin is applied per project. In a multi-project build, apply it in each project that has its own gradle.local.properties.
|
See the Gradle Plugin Portal page for other versions.
Usage
Create a file named gradle.local.properties in the project directory.
# gradle.local.properties
myRepoUrl=http://localhost:8081/repository/maven-public
featureX=true
Ideally add this file to .gitignore so it is never committed:
gradle.local.properties
Build scripts read the values as usual:
repositories {
maven { url = findProperty('myRepoUrl') ?: 'https://repo.maven.apache.org/maven2' }
}
repositories {
maven(url = findProperty("myRepoUrl") as String? ?: "https://repo.maven.apache.org/maven2")
}
Logging
| Message | Meaning |
|---|---|
|
The file exists and has at least one property (warning). |
|
An existing property was overridden. |
|
The property only exists in |
listProperties task
The plugin registers a listProperties task that reports which properties were overridden or added.
./gradlew listProperties
License
Released under the MIT License.