仅在指定的配置文件上启用maven3扩展 [英] Enable maven3 extension only on specified profile(s)

查看:144
本文介绍了仅在指定的配置文件上启用maven3扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Maven 3构建中使用了一个扩展,可以为我输出构建信息.它有点冗长,所以我只想在某些构建配置文件中运行它.但是<extensions>仅允许在主<build>中使用,而不能在配置文件中使用.

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.

所以我的问题有两个.首先,是否已有一种方法可以将扩展限制为只能在特定配置文件中运行,而我可以在pom.xml中执行此操作?其次,如果没有,那我应该如何实现呢?

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?

我最初的想法是打电话给mavenSession.getCurrentProject().getActiveProfiles()并将其与我要对其运行扩展程序的配置文件列表进行比较.但是然后我需要以某种方式将配置文件信息传递到那里.我想在pom.xml中而不是从命令行中执行此操作,但是我不确定该信息应存储在何处.

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.

推荐答案

应该起作用的一件事是使用包含以逗号分隔的配置文件名称列表的属性,理想情况下,该属性的命名方式应使连接变得明显(例如,扩展名" -artifactId».运行配置文件).然后通过-D传递它,或将其放在< properties>部分中以定义项目默认值.

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.

这篇关于仅在指定的配置文件上启用maven3扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆