Java Maven MOJO - getting information from project POM

后端 未结 5 838
醉话见心
醉话见心 2021-02-05 02:50

I am working on a maven plugin. I seem to have a hard time figuring out, what would be a good way to get POM information from project in which you execute the MOJO ?

For

5条回答
  •  不要未来只要你来
    2021-02-05 03:36

    @Component
    private MavenProject project;
    

    also works (more succinctly and intuitively) if using the new maven-plugin-annotations, which is the default for new mojos created from maven-archetype-plugin.

    EDIT (thanks to @bmargulies): although the @Component Javadoc as of 3.2 suggests using it for MavenProject, apparently that is deprecated and the suggestion is dropped as of 3.3; the idiom suggested by maven-plugin-tools-annotations (as of 3.3) is something like this (both seem to work):

    @Parameter(defaultValue="${project}", readonly=true, required=true)
    private MavenProject project;
    

提交回复
热议问题