2

Im new in Gradle enviroment and I'm developing a Spring Application with property expansion in application.properties file, like:server.port = $ {app_server_port}

Everything is working OK, when I build with gradle build command, Gradle takes the file~ / .gradle / gradle.properties and expand variables into the builded application.properties file.

My question is:

  • How can you prevent that property expansion?
  • There is any command line argument in gradle build that will make it to ignore~ / .gradle / gradle.properties and build the source with the original values?
  • There is something like gradle build --skip-global-settings?

Thanks

1 Answers1

1

You can write your build script like this:

apply plugin: 'java'

def props = new Properties()
file("local.properties").withInputStream { props.load(it) }

processResources {
  if (project.hasProperty('expand'))
    expand(props)
}

Now if you build with gradlew build -Pexpand property expansion will be done with values from local.properties.

If you build with gradlew build no property expansion will take place.


As a note, I would recommend to not put project specific properties into ~ / .gradle / gradle.properties, since this file is shared between all the projects that you build on your machine.

Thomas Kläger
  • 17,754
  • 3
  • 23
  • 34