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

unable to override default properties #3

Closed rahulj closed 10 years ago

rahulj commented 11 years ago

I wanted to keep a default value for a property in gradle.properties, and override it for only few specific environments. Right now this is not possible, because once a property is defined in gradle.properties, all env specific properties files are ignored for that property.

Currently this can be achieved by making sure you don't have any property in gradle.properties which is not common across environments, which means even if there is just one environment which needs a different value, you will end up putting it in across all environment specific files.

stevesaliman commented 11 years ago

I'm not able to reproduce this problem. When I do a build, if there is a property in an environment file, it overrides values in gradle.properties.

Are you using the latest version of the plugin?

How are you invoking Gradle, and what are your environment files named?

rahulj commented 11 years ago

I am using net.saliman:gradle-properties-plugin:1.1.1 I have following properties file: gradle.properties gradle-perf.properties and I am invoking gradle as "gradle -PenvironmentName=perf"

One thing that is different is that I have added the gradle plugin along with properties file to parent module and the tasks that I am running are defined inside child/submodule.

stevesaliman commented 11 years ago

I can reproduce this now - I don't do much with child projects...

The issue is that while Gradle itself seems to walk up the tree to find the gradle.properties file, the plugin does not walk up the tree to find gradle-.properties files.

There is a workaround:

  1. Make sure the plugin is applied to all child projects. You can either add the plugin to each child's build.xml file, or replace the apply plugin: 'properties' line in the parent project's build.gradle with: allprojects { apply plugin: 'java' }
  2. In each child project's directory, make a copy (or symlink) of each environment specific file in the parent project.

When I get some time, I'll work on an actual fix to the problem. I think it makes sense to require users to explicitly apply the plugin to the specific modules where it is needed/wanted rather than assume that the plugin should pass properties to child projects. But when the plugin is applied, it should use the same rules for locating environment specific files as Gradle itself uses to find the gradle.properties. file.

stevesaliman commented 10 years ago

I have just released version 1.2.0 of the properties plugin. This version is now multi-project aware and will allow you to do what you were describing. The project's README.md has full details.

You will still need to explicitly apply the plugin to all projects where you want it, but once done, it will inherit properties from the parent project (regardless of whether or not the parent project applied the plugin),and you will be able to override them in a child project.

The artifacts should be available on Maven Central shortly.

Thank you for bringing this up,

Steve

rahulj commented 10 years ago

works beautifully