[英]Maven plugin : parameters in configuration in pom not passed
我下面Apache的指南,以开发Java插件的说明这里。 我想按照说明使用<configuration>
标签将参数从 pom 传递给插件,但插件没有收到它们。
这是 pom.xml
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.iznogoud</groupId>
<artifactId>myPlugin-maven-plugin</artifactId>
<version>1.0</version>
<name>My First Plugin</name>
<packaging>maven-plugin</packaging>
<properties>
<maven.version>3.6.3</maven.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.annotations.version>3.6.0</maven.annotations.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${maven.annotations.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.iznogoud</groupId>
<artifactId>myPlugin-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<greeting>Greetings, carbon unit.</greeting>
</configuration>
</plugin>
</plugins>
</build>
</project>
这是插件 mojo,MyMojo.java:
package com.iznogoud;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
@Mojo( name = "sayhi")
public class MyMojo extends AbstractMojo {
@Parameter(property="greeting") // , required=true)
private String _greeting;
public void execute() throws MojoExecutionException
{
getLog().info( "Hello from MyMojo" );
getLog().info( "greeting param is " + _greeting);
}
}
从命令行传递参数确实有效,例如:
mvn com.iznogoud:myPlugin-maven-plugin:1.0:sayhi "-Dgreeting=hello from command line"
使参数成为必需的也有效。 当我设置它 required Maven 抱怨没有给出参数,除非我在命令行上传递它。
在 Windows 10、JDK 11 上使用 Maven 3.6.3,所有指令都来自命令行。
如何让<configuration>
工作? 谢谢,非常感谢!
更新:如果我使用<_greeting>
的......而不是<greeting>
在<configuration>
它的工作原理! _greeting 是 Java 变量的名称,所以好吧,有道理,但是这里的命名规则是什么? 哦,_greeting没有在命令行中运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.