我正在尝试进行一些Selenium测试,但无法将码头的开始与Maven的整合前测试阶段联系在一起。因此,我试图调查问题,并且看来Maven通常没有按照我指定的阶段执行目标。

我找到了this示例并进行了复制。我创建了一个插件,当我明确调用它时可以正常工作。但是,当我尝试将其附加到验证阶段并运行mvn validate时,我看不到“嗨!!!!”输出。它只是简单地显示了我构建成功而没有调用howdy-world目标:/(这与我的码头未从集成测试阶段开始是一致的)

通过验证阶段后,如何才能实现此目标?

这是我的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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maventest</groupId>
<artifactId>aproject</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>aproject</name>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
<pluginManagement>
    <plugins>
        <plugin>
            <groupId>com.maventest</groupId>
            <artifactId>maven-howdy-plugin</artifactId>
            <version>1.0-SNAPSHOT</version>
            <executions>
                <execution>
                    <goals>
                        <goal>howdy-world</goal>
                    </goals>
                    <phase>validate</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
    </pluginManagement>
</build>

最佳答案

您必须这样做:

<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>

  <build>
    <pluginManagement>
      <plugins>
        <plugins>
          <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
              <lifecycleMappingMetadata>
                <pluginExecutions>
                  <pluginExecution>
                    <pluginExecutionFilter>
                      <groupId>com.maventest</groupId>
                      <artifactId>maven-howdy-plugin</artifactId>
                      <versionRange>[1.0.0,)</versionRange>
                      <goals>
                        <goal>howdy-world</goal>
                      </goals>
                    </pluginExecutionFilter>
                    <action>
                      <ignore />
                    </action>
                  </pluginExecution>
                </pluginExecutions>
              </lifecycleMappingMetadata>
            </configuration>
          </plugin>
          <plugin>
            <groupId>com.maventest</groupId>
            <artifactId>maven-howdy-plugin</artifactId>
            <version>1.0-SNAPSHOT</version>
          </plugin>
        </plugins>
    </pluginManagement>
    <!-- The following will really execute the plugin -->
    <plugins>
      <plugin>
        <groupId>com.maventest</groupId>
        <artifactId>maven-howdy-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>howdy-world</goal>
            </goals>
            <phase>validate</phase>
          </execution>
        </executions>
      </plugin>
    </plugins>

  </build>
</project>


pluginManagement部分仅用于定义插件的版本和配置,但不会在生命周期内真正执行那些插件。

10-02 11:31
查看更多