Skip to content

About

Gradle Local Properties Plugin

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

Gradle Local Properties Plugin

Build Status Gradle Plugin Portal License

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.properties replace 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.

Groovy DSL (build.gradle)
plugins {
    alias(libs.plugins.infosmid.local.properties)
}
Kotlin DSL (build.gradle.kts)
plugins {
    alias(libs.plugins.infosmid.local.properties)
}
Note
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:

Groovy DSL
repositories {
    maven { url = findProperty('myRepoUrl') ?: 'https://repo.maven.apache.org/maven2' }
}
Kotlin DSL
repositories {
    maven(url = findProperty("myRepoUrl") as String? ?: "https://repo.maven.apache.org/maven2")
}

Logging

Message Meaning

local-properties:overriding with gradle.local.properties

The file exists and has at least one property (warning).

local-properties:set:<name>

An existing property was overridden.

local-properties:add:<name>

The property only exists in gradle.local.properties and was added (warning).

listProperties task

The plugin registers a listProperties task that reports which properties were overridden or added.

./gradlew listProperties

License

Released under the MIT License.

About

Gradle Local Properties Plugin

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages