Search code examples
gradlegradle.properties

Source a file in gradle


Is there a way in gradle to 'source' a file in gradle? The project has a file (project.properties) that has about one hundred properties being exported, like

export PROP1=value1
export PROP2=value2.....
export PROP100=value100

These properties are used in multiple tasks inside gradle. Question is how can I just source this file (project.properties) inside my build script?, that should have the same effect of executing the command source project.properties in a command prompt.

Doing something like below gives error - Cannot run program "source": error=2, No such file or directory

task sampleTask () {
  'source project.properties'.execute()
}

Solution

  • Looks like its possible as mentioned here https://discuss.gradle.org/t/how-to-execute-shell-command-source-or-dot-doesnt-work-with-exec/7271/7 . P.S. the sourced properties ain't gonna be availble to other processes run by other gradle tasks. Correct me if I'm wrong.