4

I have an extension I use in my Maven 3 build that outputs build information for me. It's a bit verbose so I would like to run it only in some build profiles. But <extensions> are only allowed in the main <build> and not in the profiles.

So my question is two fold. First, is there already a way to limit the extension to run only in specific profile(s) with something I can do in the pom.xml? Second, if not, then how should I implement this?

My initial thought was to call mavenSession.getCurrentProject().getActiveProfiles() and compare that to the list of profiles I want to run the extension on. But then I need to somehow pass the profile information there.. I'd like to do that in the pom.xml rather than from the command line but I'm not sure where should this info be stored.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
vertti
  • 7,539
  • 4
  • 51
  • 81
  • Old question, but I added [here](http://stackoverflow.com/a/36253007/5606016) a trick to add/change a build extension via profile, hopefully worth for some future visitors – A_Di-Matteo Mar 27 '16 at 21:46

1 Answers1

1

One thing that should work is to use a property containing a comma-separated profile name list, ideally named in a way to make the connection obvious (i.e. «extension-artifactId».run-for-profiles). Then pass that either via -D, or put it in the <properties> section to define a project default.

pyroscope
  • 4,120
  • 1
  • 18
  • 13
  • I went with your suggestion as I wasn't able to find a common way to pass arguments to extensions. – vertti Feb 15 '12 at 11:09
  • @vertti I have also encountered the same issue and I'm not quite sure I understood the proposed solution. Could you please add more details? – forhas Jul 14 '13 at 14:34
  • @forhas I implemented this to a maven plugin called `maven-build-utils`. You can checkout this [commit](https://github.com/lkoskela/maven-build-utils/commit/99a99016521b4666c061d7e317d1c48174520054) for all the details. Hope that helps. – vertti Jul 14 '13 at 17:25
  • @vertti Thank you! I will have a look. – forhas Jul 14 '13 at 19:18