stevesaliman / gradle-properties-plugin

Gradle plugin to simplify loading project properties from external environment specific files
Apache License 2.0
192 stars 28 forks source link

Properties reloaded overlaying environment properties #32

Open hopperath opened 5 years ago

hopperath commented 5 years ago

I have encountered a strange scenario when building locally every works fine, but when building on our build server, gradle reloads the system properties after loading the plugin environment properties. This causes me a problem because it overlays specific properties with their default values in gradle.properties.

Configure project : Evaluating root project 'myProject' using build file '/apps/opt/mw/OneJenkins/workspace/myProject/build.gradle'. Compiling build file '/apps/opt/mw/OneJenkins/workspace/myProject/build.gradle' using SubsetScriptTransformer. Compiling build file '/apps/opt/mw/OneJenkins/workspace/myProject/build.gradle' using BuildScriptTransformer. PropertiesPlugin:apply Loaded 14 properties from /apps/opt/mw/OneJenkins/workspace/myProject/gradle.properties PropertiesPlugin:apply Set 7 system properties from /apps/opt/mw/OneJenkins/workspace/myProject/gradle.properties PropertiesPlugin:apply Loaded 2 properties from /apps/opt/mw/OneJenkins/workspace/myProject/gradle-dev.properties PropertiesPlugin:apply Loaded 14 properties from /apps/opt/mw/OneJenkins/workspace/myProject/gradle.properties PropertiesPlugin:apply Set 7 system properties from /apps/opt/mw/OneJenkins/workspace/myProject/gradle.properties PropertiesPlugin:apply Loaded 3 properties from environment variables PropertiesPlugin:apply Loaded 0 properties from system properties PropertiesPlugin:apply Loaded 0 properties from the command line

stevesaliman commented 5 years ago

If I'm understanding the problem correctly, it looks like the issue is that the plugin is reading the project's gradle.properties file twice. Once before it loads gradle-dev.properties, and once after. That second call is the one that shouldn't be happening.

Some questions that come to mind:

  1. Is this project part of a multi-project build?
  2. Does this project have a settings.gradle file?
  3. If you add println "Gradle User Home Dir: ${gradle.gradleUserHomeDir}" to your build.gradle file (anywhere), what is the output?

The fact that everything works locally, makes me suspect that #3 will give us a clue. Gradle loads properties from ~/.gradle/gradle.properties after it processes files in the project directory, but if the gradleUserHomeDir property gets changed to point to the project directory, the project's gradle.properties file will be processed twice. I'd like to rule that out if we can.