Different build flavours

I have a Java project which I compile most of the time for release candidates (development releases), and sometimes for production release.
Now, based of the flavour I set certain properties and certain configurations.
Currently I am doing that based on a project property (-P), but it is not very elegant.
I tried creating tasks that based on the task tree different configurations will take effect, the problem is that the task graph is only ready after the configuration phase, which means by that time I am unable (or rather need to put in a lot of effort) to change the already set configurations.
Is there any elegant way in which I can achieve that?


You might be interested in my gradle-java-flavours plugin. It allows you to have common code / tests / resources but also have flavour specific code / test / resources. Each flavour is built into a separate jar

Thanks for that.
I was hoping for a simpler solution (just 2 different types of build, I know how to do it using a makefile easy, just not that fluent in gradle).
But I did notice you have a snapshot version… so, do you separate build types between snapshot and release? If you do, how?

There’s nothing automated about my release versioning. I’ve extracted my version into its own version.txt file so it’s easy to update from command line and see version history etc. Prior to a release I manually remove the -SNAPSHOT suffix. After a release I manually increment and append -SNAPSHOT again.

My solution was automating Lance’s method by using a wrapper script to change the version.txt file and then invoke gradle.