繁体   English   中英

Maven:多模块订单

[英]Maven : Multi Module order

我正在创建一个多模块 maven 项目,我想要的模块执行顺序是 Parent、Child1Plugin、Child、Child2。 Child1Plugin 还具有 CHild2 的依赖项。但到目前为止,反应器正在运行以下模块顺序:

**Reactor Summary:**
[INFO] parent 0.0.1-SNAPSHOT .............................. SUCCESS [  0.387 s]
[INFO] Child2 ............................................. SUCCESS [  2.768 s]
[INFO] Child1Plugin ....................................... SUCCESS [  1.182 s]
[INFO] Child 0.0.1-SNAPSHOT ............................... SUCCESS [  0.102 s]

***Parent:***
<groupId>com.io</groupId>
  <artifactId>ParentMod</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>parent</name>
  <description>Thisisparent</description>
  
  <modules>
    <module>Child1Plugin</module>
    <module>Child</module>
    <module>Child2</module>
  </modules>
  
  <properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
</properties>
</project>

**Child1Plugin**

@Mojo(name = "dependency-counter", defaultPhase = LifecyclePhase.COMPILE)
public class DependencyCounterMojo extends AbstractMojo{
    public void execute() throws MojoExecutionException, MojoFailureException {
       System.out.println("$$$$$$$$$$$$$$ ....Mojo execution begins.... $$$$$$$$$$$$$$");
        GenerateFeature ob=new GenerateFeature();
        ob.generationFeature();
    }
  Pom.xml:
    <parent>
        <groupId>com.io</groupId>
        <artifactId>ParentMod</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>Child1Plugin</artifactId>
    <packaging>maven-plugin</packaging>

    <dependencies>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>3.6.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>3.6.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-project</artifactId>
            <version>2.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.io</groupId>
            <artifactId>Child2</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>

   **Child2**
 public class GenerateFeature {
 public void generationFeature() {
    System.out.println("$$$$$$$$$$$$$$ ....I am generating feature files");}
  Pom.xml:
     <parent>
        <groupId>com.io</groupId>
        <artifactId>ParentMod</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>Child2</artifactId>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>
    </dependencies>

  **Child**
    <parent>
        <groupId>com.io</groupId>
        <artifactId>ParentMod</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </parent>
      <artifactId>Child</artifactId>
      
      <build>
      <plugins>    
            <plugin>
                <groupId>com.io</groupId>
                <artifactId>Child1Plugin</artifactId>
                <version>0.0.1-SNAPSHOT</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>dependency-counter</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <scope>test</scope>
                </configuration>
            </plugin>
            </plugins>
      </build>

使用上述模块,我尝试首先使用 module-Child1Plugin 安装插件,然后使用 module-Child 调用目标,最后使用 module-Child2 运行我的 cucumber 测试。但是反应堆产生了不同的顺序,因此我无法实现我想要的是。

如果 A 依赖于 B,则 B 必须在 A 之前构建。

这不仅仅是一条 Maven 规则,它是一条常识规则。

否则,A 的构建会因为 B 不存在而中断。

因此,以所述方式,无法实现所需的行为,而不是使用 Maven 或任何遵循基本逻辑的构建工具。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM