Set maven property from plugin

后端 未结 2 415
自闭症患者
自闭症患者 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.

    0 讨论(0)
  • 2021-01-07 23:33

    Maven sets properties in initialize phase. I assume that in that phase maven loads system properties. And after that maven doesn't load system properties again. If you try to add a system property after this phase than it's not loaded.

    Try to run your plugin in validate phase.

    0 讨论(0)
提交回复
热议问题