u6f6o
u6f6o

Reputation: 2190

Is is possible to specify an arbitrary properties file used by the build script?

I created kind of a getting started application that has the following structure:

Basically, each of the projects is isolated and has it's own build.gradle script. Initially I created a gradle.properties file for all projects and added the different library versions there.

Since I want to keep the library versions in one place, I'd like to import the libs.properties in all build.gradle scripts and use the library properties in the dependency section.

Nevertheless I did not find a way to specify additional properties files which can be imported in the build.gradle scripts. Ideally it would look sth. like this:

apply plugin: "java"

importProperties: "../libs.properties" 

dependencies {
    compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
}

Upvotes: 0

Views: 462

Answers (1)

Opal
Opal

Reputation: 84904

There's no out-of-the-box mechanism for what you're looking for but you may use the following piece of code (you need to rewrite all properties to ext):

build.gradle

apply plugin: 'java'

def props = new Properties()
new File('lib.properties').withInputStream { 
  stream -> props.load(stream) 
}
for(p in props) {
    project.ext[p.key] = p.value
}

repositories {
   mavenCentral()
}

dependencies {
   compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
}

lib.properties

jettyVersion=9.2.6.v20141205

Upvotes: 1

Related Questions