maven - Maven 项目属性是否具有一次性语义
问题描述
我今天观察到一个让我感到困惑的 Maven 行为。要么项目属性具有某种一次性写入语义,要么......我找不到任何可以解释这种行为的参考文档。
我可以在验证阶段动态设置 Maven 属性,以便在以后的阶段将它们评估为插件属性吗?
目标
我想根据其他属性的存在跳过配置文件中插件的执行。
计划
validate
在阶段运行 Groovy 插件。- 评估该其他属性的存在。
- 设置跳过项目属性。
- 使用 skip 属性来配置在后续阶段运行的插件。
POM 摘录
<profile>
<id>my-id</id>
<activation>
<file>
<exists>${basedir}/somefile</exists>
</file>
</activation>
<properties>
<skipIt>false</skipIt> <!-- intention: use this as default value -->
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script>
<![CDATA[
def someOtherProp = project.properties['some-other-property']
def skipIt = someOtherProp ? 'false' : 'true'
project.properties['skipIt'] = skipIt
println skipIt
println project.properties['skipIt']
]]>
</script>
</scripts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<skip>${skipIt}</skip>
</configuration>
<executions>
<execution>
<id>my-unpack</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
行为
如果some-other-property
不存在(即未设置),则打印true
两次。这意味着 Groovy 评估是正确的并且skipIt
设置正确。然而,依赖插件仍然运行my-unpack
执行。为什么?
但是,如果我在第 9 行删除<skipIt>false</skipIt>
,一切都会按我的预期工作。为什么?
解决方案
推荐阅读
- python - 使用 Python 3.6 安装 matplotlib 时出现问题
- mysql - 上一个特定月份的 MySQL
- aws-sdk - AWS SES:使用由另一个账户创建的模板发送模板化电子邮件
- python-3.x - 使用win32com在python中逐行读取.doc文件
- html - 使用 vue-cli 的tiptap 扩展按回车键创建一个新的文本字段
- r - 如何在 R 中的函数中使用 with()?
- mysql - 如何根据 SQL 中的另一列值向表中添加列
- vue.js - 动态路由器链接将 *slash* 更改为 %2F
- python - Python中的while循环和逻辑运算符 - 它是如何工作的?
- elasticsearch - nifi 将文本文件转换为 json