• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there something similar to Maven's profile in Gradle?

 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question subject says it all. I know we can use different properties file to be passed to Gradle, however Maven's profile is more then just different set of variables to be used. It is useful for grouping different logic for different profiles, so we do not end up with tons of switch/if..else all over the place.

Is there a similar feature in Gradle? If not, what is the best way to handle situation where we might have different set of task for different environments?
 
Hubert Klein Ikkink
author
Greenhorn
Posts: 13
IntelliJ IDE
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wirianto,

you can use the apply from: <scriptfile> feature from Gradle to achieve this.

You can define for each profile a separate scriptfile with all the information needed for the profile. This is just another Gradle build file, so you can use what you know from Gradle. Define dependencies, task, extra plugins, etc. For example if you have a dev and test profile you can create the files dev-profile.gradle and test-profile.gradle.

In your "main" build file you define everything that is common for all profile and build needs, plus you add the following line:
apply from: "${profile}-profile.gradle"

When you run Gradle you can pass the name of the profile using the -P option:
$ gradle -Pprofile=dev tasks
or
$ gradle -Pprofile=test tasks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic