Set maven property from plugin

后端 未结 2 437
自闭症患者
自闭症患者 2021-01-07 22:50

I\'ve read some questions here about how to set a property (most of them talked about the version number for an application) from a maven plugin. It seems there\'s no easy

2条回答
  •  庸人自扰
    2021-01-07 23:29

    Don't set it as System Property, set it as Maven Project property

    // inject the project
    @Parameter(defaultValue = "${project}")
    private org.apache.maven.project.MavenProject project;
    
    // and in execute(), use it:
    project.getProperties().setProperty("currentVersion", appCurrentVersion);
    

    See:

    • Mojo Developer Cookbook
    • MavenProject javadoc

    An edit suggested using Properties.put() instead of Properties.setProperty(). While technically, Properties implements Map, this usage is discouraged explicitly in the Properties javadoc.

提交回复
热议问题