在阶段定义插件目标
Defining plugin goal at phase
我正在尝试定义一个插件目标,以便它可以在特定阶段自动执行;比如说测试阶段。但我无法做到这一点。例如,我编写了以下 pom.xml。请注意,在我的 XML 元素中,我有一个 子元素,它是“test”。我可以使用命令“mvn antrun:run@ant-echo”执行我的目标;但是“mvn test”并没有执行那个目标。我正在使用 Maven 版本 3.8.3,我的 JDK 版本是 16.
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rjava.mvn</groupId>
<artifactId>app2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>app2</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.var1>value1</project.var1>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<!--
The command to maven execute this ant target is
mvn antrun:run@ant-echo
-->
<id>ant-echo</id>
<phase>test</phase>
<configuration>
<target name="app2">
<echo level="info">This is how you echo information into the console.</echo>
<echo level="info">Echo levels defined in Ant are the following </echo>
<echo level="info">error, warning, info, verbose, debug</echo>
<echo level="info"></echo>
<echo level="info">The following is the way to echo property values.</echo>
<echo level="info">${project.var1}</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
为了在配置的生命周期阶段执行您的插件,您必须在 <plugin>
部分指定插件目标绑定和配置:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rjava.mvn</groupId>
<artifactId>app2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>app2</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.var1>value1</project.var1>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<!--
The command to maven execute this ant target is
mvn antrun:run@ant-echo
-->
<id>ant-echo</id>
<phase>test</phase>
<configuration>
<target name="app2">
<echo level="info">This is how you echo information into the console.</echo>
<echo level="info">Echo levels defined in Ant are the following </echo>
<echo level="info">error, warning, info, verbose, debug</echo>
<echo level="info"></echo>
<echo level="info">The following is the way to echo property values.</echo>
<echo level="info">${project.var1}</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我正在尝试定义一个插件目标,以便它可以在特定阶段自动执行;比如说测试阶段。但我无法做到这一点。例如,我编写了以下 pom.xml。请注意,在我的 XML
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rjava.mvn</groupId>
<artifactId>app2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>app2</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.var1>value1</project.var1>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<!--
The command to maven execute this ant target is
mvn antrun:run@ant-echo
-->
<id>ant-echo</id>
<phase>test</phase>
<configuration>
<target name="app2">
<echo level="info">This is how you echo information into the console.</echo>
<echo level="info">Echo levels defined in Ant are the following </echo>
<echo level="info">error, warning, info, verbose, debug</echo>
<echo level="info"></echo>
<echo level="info">The following is the way to echo property values.</echo>
<echo level="info">${project.var1}</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
为了在配置的生命周期阶段执行您的插件,您必须在 <plugin>
部分指定插件目标绑定和配置:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rjava.mvn</groupId>
<artifactId>app2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>app2</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.var1>value1</project.var1>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<!--
The command to maven execute this ant target is
mvn antrun:run@ant-echo
-->
<id>ant-echo</id>
<phase>test</phase>
<configuration>
<target name="app2">
<echo level="info">This is how you echo information into the console.</echo>
<echo level="info">Echo levels defined in Ant are the following </echo>
<echo level="info">error, warning, info, verbose, debug</echo>
<echo level="info"></echo>
<echo level="info">The following is the way to echo property values.</echo>
<echo level="info">${project.var1}</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>