【问题标题】:Maven goal not attached to phaseMaven目标未附加到阶段
【发布时间】:2015-04-28 10:56:52
【问题描述】:

我正在尝试运行一些 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>

【问题讨论】:

    标签: java maven jetty lifecycle


    【解决方案1】:

    你必须这样做:

    <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 部分仅用于定义插件的版本和配置,但它不会真正在生命周期内执行这些插件。

    【讨论】:

    • 非常感谢!那行得通!但奇怪的是,当它不在 pluginManagement 中时,我在执行标签上收到一个错误:“生命周期配置未涵盖插件执行:com.maventest:maven-howdy-plugin:1.0-SNAPSHOT:howdy -world(执行:默认,阶段:验证)“
    • 这是 m2e 插件,而不是 Maven。为此,您应该在这里查看:eclipse.org/m2e/documentation/m2e-execution-not-covered.html
    • 所以这告诉我使用导致问题的插件管理。我应该忽略这个日食错误吗?
    • 我通过 m2e 配置增强了我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-20
    • 2015-08-19
    • 1970-01-01
    • 2011-07-09
    • 2019-01-25
    • 2021-07-16
    • 2017-06-08
    相关资源
    最近更新 更多