我正试图在Mojo中获得${basedir}
的值。我以为我可以看到这是一个普通的系统属性但是
System.getProperty("basedir")
返回null
。
public void execute() throws MojoExecutionException, MojoFailureException {
String baseDir = ???
}
答案 0 :(得分:6)
这是通过注入MavenProject
并调用getBaseDir()
方法完成的,如下所示:
public class MyMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
public void execute() throws MojoExecutionException, MojoFailureException {
String baseDir = project.getBaseDir();
}
}
@Parameter
用于将${project}
值<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.5</version>
<scope>provided</scope> <!-- annotations are needed only to build the plugin -->
</dependency>
注入到正在从Maven会话构建的当前项目中。{/ p>
resolves需要以下对Maven插件的依赖:
A = 5;
B = 2;
C = A/B;
C =
2.5