Maven - 无法在多模块项目中激活配置文件 [英] Maven - can't activate profiles in multi-module project

查看:363
本文介绍了Maven - 无法在多模块项目中激活配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Maven配置项目时遇到了一些困难,需要一些帮助:)

I'm experiencing some difficulties configuring our project with Maven and need some help :)

说,我有一个多模块项目,模块A和B (还有大约20个其他的)但是所有这些都继承自一些rootpom。

Say, I have a multi-module project, with modules A and B (there are ~20 others as well) but all of them inherit from some "root" pom.

我还有一个自定义maven插件,应该为模块A启用只有。

I also have a custom maven plugin that should be enabled for module A only.

插件应该以相同的方式运行所有模块,所以我将配置放在根pom中。

The plugin should run in the same way for all the modules, so I put the configuration in the root pom.

现在,插件已在配置文件中定义,因此只有在我明确要求时才会激活插件:

Now, the plugin is defined in the profile so that it will be activated only when I explicitly want so:

mvn test -PrunMyPlugin

如果我从根目录运行此命令并且如果我正在模块A的目录中运行。在模块B中,无论此配置文件如何,插件都不应该运行。

this should work if I'm running this command from the root directory and if I'm running in the directory of module A. In module B the plugin shouldn't run regardless of this profile.

另一方面

mvn test

应该永远不要调用插件。

should never invoke the plugin.

我试图在财产上使用激活,但它对我不起作用。
当我需要为每个具体模块配置插件并将所有配置保留在根pom中时,我正试图避免这种情况。

I've tried to use activation on property but it didn't work for me. I'm trying to avoid the situation when I need to configure the plugin for each concrete module and keep all the configurations in the root pom.

可能有人请提供如何做到的任何简单示例?任何帮助都非常感谢。

Could someone please provide any simple example of how to do that? Any help is highly appreciated.

提前致谢

推荐答案

定义目前,Maven 2或3不支持父级中的配置文件,然后从子级或其他配置文件激活它。有一些stackoverflow问题和答案[1]涵盖了细节。 Maven的问题跟踪器中有相关的功能请求:

Defining a profile in a parent and then activating it from a child or from another profile is not supported by either Maven 2 or 3, currently. There are a couple of stackoverflow questions and answers [1] covering the details. There are related feature requests in Maven's issue tracker:

  • https://issues.apache.org/jira/browse/MNG-3309
  • https://issues.apache.org/jira/browse/MNG-4565
  • https://issues.apache.org/jira/browse/MNG-5127

@ Raghuram建议使用< pluginManagement> 是一种可以在不重复配置的情况下完成此工作的方法。另一种是明确复制需要它的每个子模块中的配置。

@Raghuram's suggestion to use <pluginManagement> is one way you can make this work without duplicating configuration. The other is to explicitly duplicate the config in each child module requiring it.

[1]:根据当前模块激活不同的Maven配置文件?; 为什么我无法从其他个人资料中激活Maven2个人资料?

这篇关于Maven - 无法在多模块项目中激活配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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