build-parameters

Introduction: Compile-safe access to parameters supplied to a Gradle build
More: Author   ReportBugs   OfficialWebsite   
Tags:

Build Status Gradle Plugin Portal

Compile-safe access to parameters supplied to a Gradle build. Compatible with Java 8 and Gradle 7.1 or later.

Primer

Describe build parameters using a rich DSL:

plugins {
    id("org.gradlex.build-parameters")
}

buildParameters {
    group("deployment") {
        string("username") {
            description.set("The username used for deploying to the artifact repository")
            defaultValue.set("deployer")
        }
        string("password") {
            description.set("The password used for deploying to the artifact repository")
        }
    }
}

Use compile-safe accessor in you build scripts to access parameter values:

plugins {
    id("build-parameters")
}

publishing {
    repositories {
        maven {
            url = uri("https://repo.my-company.com")
            credentials {
                // username has a default and is therefore of type String
                username = buildParameters.deployment.username
                // password does not have a default and is therefore of type Provider<String>
                password = buildParameters.deployment.password.get()
            }
        }
    }
}

Run your build and pass the parameters to it using -P commandline parameters:

./gradlew :publish -Pdeployment.username="jane" -Pdeployment.password="super-secret"

Or explore available parameters by running the parameters task:

running parameters task

Usage

See the plugin's documentation page for more details on how to configure your build.

Example

You can find a basic example project setup here: samples/basics

Disclaimer

Gradle and the Gradle logo are trademarks of Gradle, Inc. The GradleX project is not endorsed by, affiliated with, or associated with Gradle or Gradle, Inc. in any way.

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools