【发布时间】:2017-12-28 06:19:22
【问题描述】:
我对 Maven 配置文件有疑问。谈到细节,我有两个配置文件,例如 profile1 和 profile2。我已经为这两个配置文件以及需要由每个配置文件单独更新的模块声明了一些属性。让我们看看下面的配置,
<profiles>
<profile>
<id>profile1</id>
<properties>
<owner>ABC</owner>
</properties>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
<profile>
<profile>
<id>profile2</id>
<properties>
<owner>XYZ</owner>
</properties>
<modules>
<module>module3</module>
<module>module4</module>
</modules>
<profile>
</profiles>
说到重点,profile1 属性 ABC 必须在 module1 和 module2 中更新,而 profile2 属性 XYZ 必须在 module3 和 module4 中更新。在构建应用程序时,我尝试了以下所有命令。
mvn clean install -Pprofile1,profile2
mvn clean install -P profile1,profile2
当我使用上述命令构建项目时,XYZ 在所有模块中都有更新。同样,当我使用以下命令时,ABC 会在所有 4 个模块中进行更新。
mvn clean install -Pprofile2,profile1
mvn clean install -P profile2,profile1
我的要求是只在module1和module2中更新ABC,在module3和module4中更新XYZ。你能告诉我,任何可以解决这个问题的解决方案。
注意:我什至尝试过以下命令, mvn clean install -Pprofile1 -Pprofile2 构建因目标或生命周期问题而失败。
-谢谢
【问题讨论】:
-
首先为什么需要为不同的模块提供配置文件? (建议:永远不要为模块使用配置文件!)...
-
我们有两个项目来构建两个具有不同属性的耳朵。这些属性必须相应地放置在需要的地方。
-
如果你必须构建两个耳朵,你应该简单地拥有两个耳朵模块......这将简单地解决问题......
-
你不理解我的问题 khmarbaise。构建耳朵文件不是问题。在构建耳朵文件时替换所有需要的属性值是个问题。再次阅读说明,如果您有任何疑问,请告诉我。
-
需要替换的属性具体在哪里,目的是什么?为什么会涉及到他们的两个模块,而不仅仅是 EAR 模块?
标签: maven maven-profiles maven-module