On 08/02/2011, at 6:22 AM, Neil Chaudhuri wrote:

> As I transition from Maven to Gradle, I am curious about how to implement 
> Maven’s profile mechanism in Gradle. I have found few resources on the topic, 
> and the one that seems the most compelling—calling applyFrom on a script 
> whose name is provided at build time from the command line—doesn’t strike me 
> as optimal. While clever, it seems a bit like an anti-pattern.

I'm curious why you might think that?


>  
> Any thoughts on best practices or other insights into simulating Maven 
> profiles is appreciated.

As others have mentioned, there are a bunch of ways to conditionally configure 
your project based on some command-line option: you can apply a script, load a 
properties file, have a switch in your build script, load the properties from a 
map, etc.

If you're using profiles to build different artifacts for different target 
environments, another approach you might consider is to instead define a task 
for each environment. Each such task would build the artifact for a single 
target environment:

jar {
    // builds the jar for the production environment
}

task testJar(type: Jar) {
    // builds the jar for the test environment
}

task devJar(type: Jar) {
    // builds the jar for the dev environment
}

This allows you to build, verify, and release the artifacts for all (or some 
subset of) environments in one build, rather than running the build once for 
each environment. To me, this is a much better approach than using a profile.

We will add more support for this approach to Gradle over time. We'd like to, 
for example, provide some way that you can declare the target environments, and 
Gradle will take care of adding and configuring the appropriate tasks for each 
environment.


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz

Reply via email to