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

Builds fail for multi-project builds if environment property file is not in rootDir #14

Closed scottdotau closed 10 years ago

scottdotau commented 10 years ago

Hey Guys,

This is a question more than anything, was just wondering if this is expected behaviour. I am currently building a 'whitelabel' project, and am using this plugin (thanks!) for filtering my properties files.

Only thing that has been annoying me a little, is the need to have gradle-<environmentName>.properties in the rootDir project (though is fine if it doesn't exist in the subproject - inherits gradle.properties).

Build fails if this is not there, and as I am setting environmentName dynamically, the rootDir gets quite messy (gradle-<environmentName>.properties files not just in sub-projects, but rootDir also - mainly empty).

Example:

+ shared
+ project1
|- gradle.properties
|- gradle-env1.properties
|- gradle-env3.properties
+ project2
|- gradle.properties
|- gradle-env1.properties
|- gradle-env2.properties
|- gradle-env3.properties
gradle.properties
gradle-env1.properties
gradle-env2.properties

I would expect all of these to work (even if environment properties file is missing - as the gradle.properties file exists), however: gradle :project1:build -PenvironmentName=env1 works gradle :project1:build -PenvironmentName=env2 works gradle :project1:build -PenvironmentName=env3 fails (No environment files were found for the 'env3' environment)

Basically, I don't want to have to have all of the environment property files within my rootDir. However, if you pass through environmentName - it MUST be there (but not in subprojects - even if they are the target you are building), or it fails.

stevesaliman commented 10 years ago

The plugin looks for at least one environment property file when it applies the plugin. It can be found in the project directory, or in any of the parent projects up the tree. If it can't be found, the build will fail.

In this case, if you apply the plugin to the sub-projects, but not the root project, you won't need to have any environment property files in the root project, but you would need them in each sub-project.

scottdotau commented 10 years ago

Thanks @stevesaliman, turns out this was my mistake - sorry for the inconvenience :).

I was applying the plugin to all projects within the subprojects closure, where I should have only been applying them to the web projects that I am targeting.

+ web_project1
+ web_project2
+ shared_web_project
+ shared_api

Each web project depends on shared_api (java task) and shared_web_project (war task), so when kicking off gradle :web_project1:build, property files in each of the shared project would be filtered using values in web_project1 folder before being built.

As the project depends on shared_web_project's war task, I think it was looking for environment files within its folder (where I was expecting to only need them in web_project1.

This was fixed by removing the properties plugin from shared_web_project & shared_api, and only into web_project tasks.

Thanks, Scott