gpt4 book ai didi

java - 从插件设置 Maven 属性

转载 作者:太空狗 更新时间:2023-10-29 22:52:46 25 4
gpt4 key购买 nike

我在这里阅读了一些关于如何从 Maven 插件设置属性的问题(其中大部分讨论了应用程序的版本号)。似乎没有简单的方法可以做到这一点,我发现的最佳解决方案是拥有一个 filter.properties 文件,该文件从插件更新并由主 pom 文件使用来过滤所需的资源。

从 Maven 文档 (Maven filter plugin) 中阅读此内容后,我尝试了另一种解决方案:

Variables can be included in your resources. These variables, denoted by the ${...} delimiters, can come from the system properties, your project properties, from your filter resources and from the command line.

我发现有趣的是可以从系统属性中读取变量。所以,我修改了我的插件来设置这样的系统属性:

System.setProperty("currentVersion", appCurrentVersion);

然而,过滤后的资源似乎并没有读取这个值。谁能告诉我这种方法有什么问题吗?

更新:我在验证阶段运行我的插件。

非常感谢。

最佳答案

不要将其设置为系统属性,将其设置为 Maven 项目属性

// inject the project
@Parameter(defaultValue = "${project}")
private org.apache.maven.project.MavenProject project;

// and in execute(), use it:
project.getProperties().setProperty("currentVersion", appCurrentVersion);

参见:


编辑建议使用 Properties.put() 而不是 Properties.setProperty()。虽然从技术上讲,Properties 实现了 Map,但明确不鼓励这种用法 in the Properties javadoc .

关于java - 从插件设置 Maven 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7553530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com