tags:

views:

272

answers:

1

I have a maven module which has some dependencies. In a certain profile, I want to exclude some of those dependencies (to be exact, all dependencies with a certain group id). They however need to be present in all other profiles. Is there a way to specify exclusions from the dependencies for a profile?

+3  A: 

To my knowledge, no, you can't deactivate dependencies (you can exclude transitive dependencies but this is not what you are asking for) and yes, what you are currently doing with the POM (manually editing it) is wrong.

So, instead of removing dependencies, you should put them in a profile and either:

  • Option #1: use the profile when required or
  • Option #2: mark the profile as activated by default or put it in the list of active profiles and deactivate it when required.

A third option would be (not profile based):

  • Option #3: separate things in two separated modules (as you have separated concerns) and use inheritance.
Pascal Thivent
The problem with that approach is that I need the dependencies to be there pretty much all the time. I need to create the target platform maybe once every 3 months. So having to specify a profile on every build is much more of a hassle than editing the POM by hand. Profiles marked active by default unfortunately get deactivated when another profile is activated, so that won't help me either as there very often is another profile active.
Thomas Lötzer
I won't argue about profiles and how you are using them, I'm just giving you possible solutions. But no, you can't deactivate dependencies (you can only exclude transitive dependencies). If you don't want them, create another module.
Pascal Thivent