Activate profile when a certain Maven goal is run

3k Views Asked by At

I'm looking for a generic solution to enable a Maven profile when a certain Maven goal is run. For example, if I run

mvn site

I also want to activate the profile reporting automatically. I don't want to do it manually, e.g., using:

mvn site -Preporting

I expected that in the activation part of a profile I can specify a Maven goal, triggering the profile to get enabled, but this doesn't seem the case.

Another idea was that I could somehow configure a property to get set if a certain goal is run, because a profile can be activated by a property. But I haven't really found a way how to do that.

Is there a generic solution?

1

There are 1 best solutions below

0
On

I doubt this is a good idea, really.

Maven adheres to the concept of repeatable builds. If running "mvn site" somehow changes the local build configuration so that this (or the next Maven command) runs with a profile enabled means subsequent builds might behave differently.

Instead, you may be able to attach the reporting requirements to the mvn site goal (or another goal).

Therefore, mvn site will also run reporting.