英文:
Maven : Multi Module order
问题
我正在创建一个多模块的Maven项目,我想要的模块执行顺序是Parent、Child1Plugin、Child、Child2。另外,Child1Plugin依赖于Child2。但是目前反应堆(reactor)正在按照以下模块顺序运行:
反应堆摘要:
[INFO] parent 0.0.1-SNAPSHOT .............................. 成功 [ 0.387 秒]
[INFO] Child2 ............................................. 成功 [ 2.768 秒]
[INFO] Child1Plugin ....................................... 成功 [ 1.182 秒]
[INFO] Child 0.0.1-SNAPSHOT ............................... 成功 [ 0.102 秒]
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();
}
}
Child2模块:
public class GenerateFeature {
public void generationFeature() {
System.out.println("$$$$$$$$$$$$$$ ....I am generating feature files");
}
}
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>
使用上述模块,我尝试首先使用模块Child1Plugin安装插件,然后使用模块Child调用目标,最后使用模块Child2运行我的Cucumber测试。但是由于反应堆产生了不同的顺序,我无法实现我想要的目标。
英文:
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.
答案1
得分: 3
如果A依赖于B,那么在构建A之前必须构建B。
这不仅仅是Maven的规则,而是常识的规则。
否则,构建A将会失败,因为B不存在。
因此,以所述方式,无论是使用Maven还是遵循基本逻辑的任何构建工具,都无法实现所期望的行为。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论