简体   繁体   中英

Maven : Multi Module order

I'm creating a Multi-module maven project and module execution order that I want is Parent,Child1Plugin,Child,Child2. Also Child1Plugin has dependency of CHild2.But as of now the reactor is running the following order of modules:

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

Using above modules I m trying to first install plugin using module-Child1Plugin and then invoke the goal using the module-Child and atlast run my cucumber tests using module-Child2.But reactor is producing a different order due to which I am unable to achieve what i want.

If A has a dependency on B, then B has to be build before A.

This is not just a Maven rule, it is a rule of common sense.

Otherwise, the build of A would break because B would not exist.

So in the stated way, the desired behaviour could not be achieved, not with Maven, or with any build tool that follows basic logic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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