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