Activate profile when a certain Maven goal is run
Asked Answered
B

1

9

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?

Blinnie answered 4/8, 2012 at 21:1 Comment(6)
The first question which comes to my mind is: Why do you need that? What would you like to achieve?Olpe
E.g. to load additional plugins only if a certain goal is executed.Blinnie
That's simply not possible, cause plugins can be bound to particular lifecycle phases but not to goals, cause a goal is inside a plugin from that it does not make sense. May be you can elaborate more what you like to achieve.Olpe
Is site a goal? I think it's a lifecycle ("site") and a lifecycle phase ("site"). (In your usage the latter.) You could hook your plugins onto the other site (lifecycle) phases, such as pre-site and post-site.Glissando
Duplicate of #15964670Minos
Possible duplicate of How to activate profile based on goal being executedDuckweed
J
0

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.

Jackson answered 1/4, 2022 at 7:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.