Gradle - Include Properties File

Viewed 83108

How would I include a properties file in Gradle?

For example in Ant, I could do the following:

<property file="${basedir}/build.properties" />
10 Answers

In your task (jar or any other task) you can do this way to include any file into the destination folder

jar{

    //jar task related code

   from("src/main/......(source)") { 
     include 'xxx.properties' into('com/.....(destination)') 

   }

}

This is for Kotlin DSL (build.gradle.kts):

import java.util.*
// ...

val properties = Properties().apply {
    load(rootProject.file("local.properties").reader())
}
val prop = properties["propName"]

In Android projects (when applying the android plugin) you can also do this:

import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
// ...

val properties = gradleLocalProperties(rootDir)
val prop = properties["propName"]
Related