Maven-根据项目属性激活配置文件 [英] Maven - activate profile based on project property

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

问题描述

我正在尝试实现以下目标:

Hi I am trying to achieve something like this:

在父母pom中,我有

<profile>
  <activation>
    <property>
      <name>Compile</name>
      <value>${project.artifactId}</value>
    ...

因此,如果我在父pom下运行mvn -DCompile=mod1 install,它将仅将配置文件设置应用于模块1,而不会应用于其他模块.

so that if I run mvn -DCompile=mod1 install under the parent pom, it will only apply the profile settings to module 1, but not the others.

类似地,如果我有

<profile>
  <activation>
    <property>
      <name>Compile</name>
      <value>${project.packaging}</value>
    ...

然后在父pom下运行mvn -DCompile=war install,它将仅将配置文件设置应用于将打包为war的配置,而不应用于jar或pom.

then running mvn -DCompile=war install under the parent pom, it will only apply the profile settings to those to be packed as war but not jar nor pom.

我尝试过,但是没有按预期工作.我有什么想念的吗?请帮忙.

I tried but it didnt work as expected. Did I miss anything? Please help.

P.S.无需提出解决方法,因为我只对这种方法感兴趣.如果是这样,只需简单地回答就没有理由是不可能的.谢谢

P.S. no need to suggest workarounds as I am only interested on this method. Simply answer it is not possible with reason if thats the case. Thank you

推荐答案

自...以来,它将不起作用.

It won't work since...

开始于:

  • Profile activation works with system properties and not with Maven properties.

以及为什么从父辈到子辈都不起作用:

And why it would not work from the parent down to the children:

  • 父POM中的属性在您的子POM出现之前就已展开.

许多人都在您之前来到这里,但失败了.

Many have gone here before you and failed.

一个人可能想知道您实际上是想做什么.您是否要从同一个源项目中构建不同的工件?也许您需要更多的Maven模块来处理事情.

One might wonder what you are really trying to do. Are you building different artifacts from the same source project? Perhaps you need a few more Maven modules to take care of things.

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

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