[英]Cannot set parameter using annotations on a maven plugin
我正在尝试开发一个maven插件,当我使用@Parameter注释时它不起作用。
我的依赖:
...
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.3</version>
</dependency>
...
我用的时候:
@Parameter (property = "resources")
protected String resources;
资源保持为null,当我更改它时:
/**
* @parameter expression="${resources}"
*/
protected String resources;
资源得到满足。 我执行我的插件:
mvn example:goal -Dresources=whatever
这是我的Mojo宣言:
@Mojo(name = "example", defaultPhase = LifecyclePhase.PROCESS_RESOURCES)
public class ExampleMojo extends AbstractMojo {
任何想法为什么会发生这种情况,我需要做些什么来使这个注释按预期工作?
好吧,我有两个问题。 一个原因是我和一个已知的bug在更新版本的mvn中解决了,而不是在这里安装的版本。
首先是我造成的问题:其实我的Mojo声明是这样的:
/**
* my goal
*
* @goal example
* @phase process-sources
*/
@Mojo(name = "example", defaultPhase = LifecyclePhase.PROCESS_RESOURCES)
public class ExampleMojo extends AbstractMojo {
由于@goal和@phase的评论,这使我的插件工作。 所以我认为@Mojo正在做这项工作,但我错了。
第二个问题是这个已知的错误: http : //jira.codehaus.org/browse/MNG-5346
有一些解决方案,比如将moven-plugin-plugin依赖项和一些描述符添加到mojo的pom中。 但我选择将我的maven更新为3.2.3并删除带注释的注释(@goal和@phase),一切都按预期开始工作。
现在我的mojo看起来像这样:
@Mojo(name = "example", defaultPhase = LifecyclePhase.PROCESS_RESOURCES)
public class ExampleMojo extends AbstractMojo {
@Parameter(property = "resources")
protected String resources;
/**
* do something nice
* @throws MojoExecutionException
*/
public void execute() throws MojoExecutionException {
System.out.println(resources);
}
}
为了完整起见,这是我的pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.package</groupId>
<artifactId>example</artifactId>
<packaging>maven-plugin</packaging>
<version>0.1-SNAPSHOT</version>
<name>Maven Mojo</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<showDeprecation>true</showDeprecation>
<compilerArgument>-Xlint:all,-serial</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.3</version>
</dependency>
</dependencies>
</project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.