我如何才能使 Maven 模块仅在父部署时进入测试阶段?

How can I make a Maven module only go until the test phase when the parent gets deployed?

我正在处理一个多模块项目。我们的模块之一是 tests 项目,它测试其他模块。

第一个问题:这是一个很好的练习吗?

Maven 构建生命周期阶段是:

  1. validate
  2. compile
  3. test
  4. package
  5. integration-test
  6. verify
  7. install
  8. deploy

安装或部署父模块时,如何让tests模块只执行到test阶段,即跳过包和后续阶段?由于此模块的唯一目的是测试其他模块。

我认为这是一个 jar 项目。看看Plugin Bindings for Default Lifecycle Reference

maven-jar-pluginmaven-install-pluginmaven-deploy-plugin 插件的默认执行绑定到 pom.xml

中的 none 阶段
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>default-jar</id>
            <phase>none</phase>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.5.2</version>
    <executions>
        <execution>
            <id>default-install</id>
            <phase>none</phase>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.2</version>
    <executions>
        <execution>
            <id>default-deploy</id>
            <phase>none</phase>
        </execution>
    </executions>
</plugin>