Gradle 2.0 - Correct way to load java properties file?

In Gradle, you can load data from a properties file via:

apply from: "version.properties"

      

As of Gradle 2.0, this generates a warning:

"Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtensi‌​on.html for information on the replacement for dynamic properties."

      

What are the canonical means of the same behavior in the latest and greatest version of Gradle?

I can get around this by defining a helper method of course, but I'm curious if there is a more concise way.

+3


source to share


1 answer


The correct way to load data from non-property files gradle.properties

has always been to use the Java class Properties

:

def versionProperties = new Properties()
file("version.properties").withReader { versionProperties.load(it) }

// Perhaps a future Groovy version could simplify this to:   
def versionProperties = file("version.properties").loadProperties()

      



Loading properties through apply from: "version.properties"

only ever worked coincidentally, and only if all property values ​​were numbers (because then the properties file syntax becomes a subset of Groovy syntax). The deprecation warning will already occur in 1.x (at least for last year's version 1.x). 2.0 finally removed the ability to inject properties on the fly without declaring them with def

or ext.

, which explains why it fails.

+7


source







All Articles