无法从自定义maven MOJO获取系统参数

发布于 2025-01-11 07:17:01 字数 1909 浏览 0 评论 0原文

我尝试在自定义 Maven MOJO 中获取系统属性的值,如下所述: https://maven.apache.org/developers/mojo-api-specification.html。 我尝试从以下命令行获取值的属性是“releaseVersion”:

mvn -DdevelopmentVersion=0.0.0.7-SNAPSHOT -DreleaseVersion=0.0.0.6 -Dresume=false release:clean release:prepare release:perform

在我的自定义 MOJO 中,我尝试使用以下代码将系统属性注入属性中:

@Mojo(name = "release-change", defaultPhase = LifecyclePhase.COMPILE)
public class ReleaseChangesMojo extends AbstractMojo
{
    @Parameter(property = "releaseVersion", defaultValue = "${releaseVersion}", required = true)
    private String releaseVersion;

我的 pom.xml 包含此代码来启动我的 MOJO :

      <plugin>
        <groupId>fr.my.plugin</groupId>
        <artifactId>my-release-maven-plugin</artifactId>
        <version>0.0.5</version>
      </plugin>
    </plugins>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.5.3</version>
          ...
          <configuration combine.self="override">
            <preparationGoals>clean verify</preparationGoals>
            <goals>deploy</goals>
            <completionGoals>my-release:release-change</completionGoals>
          ...
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>

但在执行时,我收到以下错误:

[ERROR] 无法在项目示例上执行目标插件:my-release-maven-plugin:0.0.5:release-change(default-cli):参数'目标 fr.my.plugin:my-release-maven-plugin:0.0.5:release-change 的releaseVersion'缺失或无效 -> [帮助 1]

您知道为什么系统属性没有注入到我的 MOJO 中吗?

I try to get the value of a system property in a custom maven MOJO, like described here : https://maven.apache.org/developers/mojo-api-specification.html.
The property which I try to get the value is "releaseVersion" from the following command line :

mvn -DdevelopmentVersion=0.0.0.7-SNAPSHOT -DreleaseVersion=0.0.0.6 -Dresume=false release:clean release:prepare release:perform

In my custom MOJO, I try to inject the system property in an attribute with the following code :

@Mojo(name = "release-change", defaultPhase = LifecyclePhase.COMPILE)
public class ReleaseChangesMojo extends AbstractMojo
{
    @Parameter(property = "releaseVersion", defaultValue = "${releaseVersion}", required = true)
    private String releaseVersion;

My pom.xml contains this to launch my MOJO :

      <plugin>
        <groupId>fr.my.plugin</groupId>
        <artifactId>my-release-maven-plugin</artifactId>
        <version>0.0.5</version>
      </plugin>
    </plugins>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.5.3</version>
          ...
          <configuration combine.self="override">
            <preparationGoals>clean verify</preparationGoals>
            <goals>deploy</goals>
            <completionGoals>my-release:release-change</completionGoals>
          ...
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>

But on execution, I get the following error :

[ERROR] Failed to execute goal plugin:my-release-maven-plugin:0.0.5:release-change (default-cli) on project exemple: The parameters 'releaseVersion' for goal fr.my.plugin:my-release-maven-plugin:0.0.5:release-change are missing or invalid -> [Help 1]

Do you have any idea why the system property is not injected in my MOJO ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文