Search code examples
mavenmaven-plugin

maven plugin - get artifactId of plugin in Mojo


Is it possible to get the artifactId of the current Mojo?

@Mojo(...)
public class MyMojo extends AbstractMojo {
    @Parameter(property = "project")
    private MavenProject project;
    @Parameter(property = "inputDirectory", defaultValue = "${project.basedir}/src/main/${artifact id of the plugin}")
    private File inputDirectory;

   ...

I could hardcode the artifact id of the plugin, but I would rather get it dynamically.


Solution

  • BTW what comes into my mind is that you are using old style injection

    @Parameter(property = "project")
    private MavenProject project;
    
    @Parameter(property = "inputDirectory", defaultValue = "${project.basedir}/src/main/${artifact id of the plugin}")
    private File inputDirectory;
    

    They should look like this:

    The expression values for defaultValue are documented here: http://maven.apache.org/ref/3.1.1/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html depending on your used Maven version.

    @Parameter(defaultValue = "${project}, required = true, readonly = true)
    private MavenProject project;
    
    @Parameter(defaultValue = "${project.basedir}/src/main/${artifact id of the plugin}", property = "inputDirectory", required = true)
    private File inputDirectory;