如果在“pluginManagement”中添加“plugin”标签

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”标签,一切正常


示例Mojo.java


@Mojo(name = "example-gole")

公共类 ExampleMojo 扩展 AbstractMojo {


@Parameter(property = "employee")

private Employee employee; 


@Override

public void execute() throws MojoExecutionException {

    getLog().info(employee);

}

}


execute 方法向所有属性显示空输出


雇员.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 配置来自其调用者。


守着星空守着你
浏览 221回答 1
1回答

长风秋雁

它现在对我有用。使用“插件”“配置”标签代替“执行”“配置”标签<pluginManagement><plugins>&nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.example.groupid</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>artifact-example-maven-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.0-SNAPSHOT</version>&nbsp; &nbsp; &nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <id>mojo-plugin-id</id>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>example-gole</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <phase>integration-test</phase>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; &nbsp; &nbsp; </executions>&nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <employee>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <firstName>MyFirstName</firstName>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <middleName>MyMiddleName</middleName>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <lastName>MyLastName</lastName>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </employee>&nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; </plugin></plugins>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python