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

environment system property not applied #4

Closed pepov closed 10 years ago

pepov commented 10 years ago

When I use the plugin no environment system properties can be applied on previously defined properties. (non existent properties are ok)

Example property:

cat gradle.properties 
myprop=1

Without properties plugin:

ORG_GRADLE_PROJECT_myprop=3 gradle properties | grep myprop
myprop: 3

With properties plugin applied on the project:

ORG_GRADLE_PROJECT_myprop=3 gradle properties | grep myprop
filterTokens: ...
myprop: 1

It does not work using GRADLE_OPTS either:

GRADLE_OPTS="-Dorg.gradle.project.myprop=3" gradle properties | grep myprop
filterTokens: ...
myprop: 1
stevesaliman commented 10 years ago

It plugin does not support environment variables or system properties. I'll try to add that support as soon as I can. I'll need to figure out where these 2 levels fit into the order of precedence for setting a property.

pepov commented 10 years ago

I did not checked this in the code yet, but if I can help please let me know and I will try to take the time for fixing this.

System properties are the highest precedence and right after comes the env vars I suppose.

stevesaliman commented 10 years ago

I've published a fix to Maven's snapshot repository (https://oss.sonatype.org/content/repositories/snapshots/) as version 1.3.0-SNAPSHOT. The precedence that made the most sense based on the standard Gradle behavior was as follows:

  1. Command line properties set with -P have the highest precedence, and override all other ways of setting a value.
  2. System properties set with -D, as documented in section 14.2 of the Gradle user guide, come next.
  3. Environment variables, as documented in the Gradle user guide, come next.
  4. Various files are handled as before. Complete documentation is in the project README.md file.

Fixing the plugin was pretty straightforward, but the unit tests were quite the challenge. I've never tried to set an environment variable in Java before - it is not easy :-)

If you get some time, give it a try and let me know if it fixes your issue, and I'll do a formal release.

Thank you for pointing out this missing requirement,

Steve

pepov commented 10 years ago

Very nice of you taking care of this, now it works just like I would expect! Thank you!

stevesaliman commented 10 years ago

I just created the official 1.3.0 release, it should be available on Maven Central in the next hour or so.