• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 218
VI Editor Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 13
IntelliJ IDE
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic