如果在“ pluginManagement”中添加了“ plugin”标记,则在java代码中将maven配置标记值设置为null(请参见以下代码)

时间:2018-09-07 04:44:45

标签: java maven

pom.xml

<pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.example.groupid</groupId>
                <artifactId>artifact-example-maven-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>

                <executions>
                    <execution>
                        <id>mojo-plugin-id</id>
                        <goals>
                            <goal>example-gole</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                            <employee>
                                <firstName>MyFirstName</firstName>
                                <middleName>MyMiddleName</middleName>
                                <lastName>MyLastName</lastName>
                            </employee>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>

在Java类中将配置标记值设置为null(如下所示,java类),但是如果我删除了“ pluginManagement”标记,则一切正常

ExampleMojo.java

@Mojo(name = "example-gole")

公共类ExampleMojo扩展AbstractMojo {

@Parameter(property = "employee")
private Employee employee; 

@Override
public void execute() throws MojoExecutionException {
    getLog().info(employee);
}

}

执行方法对所有属性显示空输出

Employee.java

public class Employee implements Serializable {

private static final long serialVersionUID = 1L;

private String firstName;
private String middleName;
private String lastName;

// consider constructor, getter and setter, hashcode, eqauls, toString is available

}

更多信息

创建自定义的maven插件,以上的Java类来自maven插件,但上述pom.xml配置来自其调用者。

1 个答案:

答案 0 :(得分:0)

现在正在为我工​​作。使用“插件”“配置”标签代替“执行”“配置”标签

<pluginManagement>
<plugins>
    <plugin>
        <groupId>com.example.groupid</groupId>
        <artifactId>artifact-example-maven-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>

        <executions>
            <execution>
                <id>mojo-plugin-id</id>
                <goals>
                    <goal>example-gole</goal>
                </goals>
                <phase>integration-test</phase>
            </execution>
        </executions>

        <configuration>
            <employee>
                <firstName>MyFirstName</firstName>
                <middleName>MyMiddleName</middleName>
                <lastName>MyLastName</lastName>
            </employee>
        </configuration>

    </plugin>
</plugins>