How do I set a project property in settings.gradle, for use in build.gradle?

I would like to set a property in the settings.gradle file, and then use that property in the build.gradle file.

I tried the following:


gradle.rootProject.ext.username = "foo"
gradle.rootProject.ext.password = "bar"


buildscript {

    ext {
        grailsVersion = project.grailsVersion
    repositories {
            url = "http://dc1artifctry01:8081/artifactory/releases"
            credentials {
                username project.username
                password project.password
    dependencies {
        // ...

But this results in the following error:

FAILURE: Build failed with an exception.

* Where:
Settings file 'C:\eclipse_ws\test_build\settings.gradle' line: 2

* What went wrong:
A problem occurred evaluating settings 'test_build'.
> The root project is not yet available for build.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating settings 'test_build'.
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$
        at org.gradle.configuration.DefaultScriptTarget.addConfiguration(
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(
        at org.gradle.initialization.ScriptEvaluatingSettingsProcessor.applySettingsScript(
        at org.gradle.initialization.ScriptEvaluatingSettingsProcessor.process(
        at org.gradle.initialization.PropertiesLoadingSettingsProcessor.process(
        at org.gradle.initialization.NotifyingSettingsProcessor$1.create(
        at org.gradle.initialization.NotifyingSettingsProcessor$1.create(
1 Like

I do it as follows in settings.gradle.kts (using kotlin, but a groovy version should be similar enough):

    rootProject.extra.set("someProperty", "someValue")