Gradle - Include Properties File

前端 未结 9 1044
天命终不由人
天命终不由人 2020-12-08 04:13

How would I include a properties file in Gradle?

For example in Ant, I could do the following:



        
9条回答
  •  眼角桃花
    2020-12-08 04:46

    What you propably are looking for is something like:

        Properties props = new Properties()
        props.load(new FileInputStream("$project.rootDir/profile/"+"$environment"+".properties"))
        props.each { prop ->
          project.ext.set(prop.key, prop.value)
        }
    

    Your properties should then be accessible directly through their name. I.e.:

      println "$jdbcURL"
      println project.jdbcURL
    

    Theres probably a reason (shadowing?) why its a bad idea to do this? Not sure why its not supported out of the box or can be found somewhere else.

提交回复
热议问题