在 Maven 中定义条件配置文件时,对顺序很重要感到困惑
我有一个可配置属性line.ending,我在项目构建的组装阶段使用它来指定应用程序属性文件的行结束类型。为此,我创建了两个配置文件 LF_DOS 和 LF_UNIX,这样当我启动 :
mvn install
或
mvn install -P LF_DOS
line.ending 时等于“dos”,并且当我launch :
mvn install -P LF_UNIX
line.ending等于'unix'。
我的第一次尝试很简单:
<profile>
<id>LF_UNIX</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<line.ending>unix</line.ending>
</properties>
</profile>
<profile>
<id>LF_DOS</id>
<activation>
<property>
<name>!line.ending</name>
</property>
</activation>
<properties>
<line.ending>dos</line.ending>
</properties>
</profile>
不幸的是,无论 LF_UNIX 设置与否,这总是给我 line.ending=dos 。奇怪......但是,让我更困惑的是,我只是通过更改配置文件声明顺序来解决问题,如下所示:
<profile>
<id>LF_DOS</id>
<activation>
<property>
<name>!line.ending</name>
</property>
</activation>
<properties>
<line.ending>dos</line.ending>
</properties>
</profile>
<profile>
<id>LF_UNIX</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<line.ending>unix</line.ending>
</properties>
</profile>
这完全按照我想要的方式工作。
我的问题是:这是一个错误吗?或者是否需要了解 Maven 配置文件,这是一种使配置文件顺序声明在这种情况下特别重要的限制?
I have a configurable property line.ending that I used during the assembly phase of the building of my project to specify the line ending type of my application property files. For that I have created two profiles LF_DOS and LF_UNIX, so that when I launch :
mvn install
or
mvn install -P LF_DOS
line.ending equals 'dos', and when I launch :
mvn install -P LF_UNIX
line.ending equals 'unix'.
My first attempt to do this was simply :
<profile>
<id>LF_UNIX</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<line.ending>unix</line.ending>
</properties>
</profile>
<profile>
<id>LF_DOS</id>
<activation>
<property>
<name>!line.ending</name>
</property>
</activation>
<properties>
<line.ending>dos</line.ending>
</properties>
</profile>
Unfortunately, this always gave me line.ending=dos, whatever LF_UNIX is set or not. Weird... But, the more confusing to me, is that I solved the problem just by changing the profile declaration order, like this :
<profile>
<id>LF_DOS</id>
<activation>
<property>
<name>!line.ending</name>
</property>
</activation>
<properties>
<line.ending>dos</line.ending>
</properties>
</profile>
<profile>
<id>LF_UNIX</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<line.ending>unix</line.ending>
</properties>
</profile>
This works exactly like I want.
My questions is : is this a bug ? Or is it something to know about maven profiles, a kind of limitation that makes profiles order declaration particularly matter in such a case ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
困惑在于您对配置文件激活如何工作的理解。
您认为这:
意味着如果我没有设置名为“line.ending”的 Maven 属性,请激活此配置文件。如果我没有在命令行上指定 -Dline.ending=X,则激活此配置文件的真正含义是什么。因此,除非您运行这样的命令:
您正在激活此配置文件,从而将值设置为 dos。
The confusion lies in your understanding of how profile activation works.
You think that this:
means if I don't have a maven property named "line.ending" set, activate this profile. What it really means if I didn't specify -Dline.ending=X on the command line, activate this profile. So unless you run something like this:
You are activating this profile and thus having the value set to dos.