Accessing ext properties from within "buildscript" closure


(Gunnar Morling) #1

Hi,

I’m trying to centralize the repository URLs of my build script as external variables:

ext {
    jbossPublicUrl = 'http://repository.jboss.org/nexus/content/groups/public/'
}

Everything works as expected when referring to this property from within the “allprojects” closure:

allprojects {
    repositories {
        mavenRepo name: 'jboss-public', url: rootProject.jbossPublicUrl
    }
}

I don’t know though how to refer to the property from within the “buildscript” closure:

buildscript {
    repositories {
        //doesn't work, "rootProject" is not known here
        mavenRepo name: 'jboss-public', url: rootProject.jbossPublicUrl
    }
 }

Is there any way to accomplish this task?

Many thanks,

–Gunnar


(Luke Daley) #2

You have to declare the properties inside ‘buildscript {}’ to be able to access them there.

The buildscript {} block is evaluated before anything else in the script (regardless of location in file).