maven插件 - 在Mojo中获取插件的artifactId

时间:2015-05-05 06:48:38

标签: maven maven-plugin

是否可以获取当前Mojo的artifactId?

@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;

   ...

我可以硬编码插件的工件ID,但我宁愿动态地获取它。

1 个答案:

答案 0 :(得分:0)

BTW我想到的是你正在使用旧式注射

@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:

defaultValue的表达式值在此处记录: http://maven.apache.org/ref/3.1.1/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html取决于您使用的Maven版本。

@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;