Apache Maven Accessing the project information


The plugin can, among others, access information about the current Maven project being built.

@Mojo(name = "project")
public final class ProjectNameMojo extends AbstractMojo {

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

    public void execute() throws MojoExecutionException, MojoFailureException {
        getLog().info("Hello, this is " + project.getName());

The above example would print in the console the name of the Maven project it is run on, which is specified in the <project>/<name> element of its POM.

The MavenProject class used in the plugin requires a dependency of maven-core with a (default) compile scope in the plugin's POM:


Furthermore, using annotations requires the following dependency in the plugin's POM:

  <scope>provided</scope> <!-- annotations are needed only to build the plugin -->