Maven:多模块顺序

huangapple go评论77阅读模式
英文:

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:***
&lt;groupId&gt;com.io&lt;/groupId&gt;
  &lt;artifactId&gt;ParentMod&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
  &lt;name&gt;parent&lt;/name&gt;
  &lt;description&gt;Thisisparent&lt;/description&gt;
  
  &lt;modules&gt;
  	&lt;module&gt;Child1Plugin&lt;/module&gt;
  	&lt;module&gt;Child&lt;/module&gt;
  	&lt;module&gt;Child2&lt;/module&gt;
  &lt;/modules&gt;
  
  &lt;properties&gt;
    &lt;maven.compiler.source&gt;1.7&lt;/maven.compiler.source&gt;
    &lt;maven.compiler.target&gt;1.7&lt;/maven.compiler.target&gt;
&lt;/properties&gt;
&lt;/project&gt;

**Child1Plugin**

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

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

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

	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;junit&lt;/groupId&gt;
			&lt;artifactId&gt;junit&lt;/artifactId&gt;
			&lt;version&gt;4.12&lt;/version&gt;
			&lt;scope&gt;test&lt;/scope&gt;
		&lt;/dependency&gt;
        &lt;dependency&gt;
			&lt;groupId&gt;info.cukes&lt;/groupId&gt;
			&lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
			&lt;version&gt;1.2.5&lt;/version&gt;
		&lt;/dependency&gt;
    &lt;/dependencies&gt;

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

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.

huangapple
  • 本文由 发表于 2020年8月1日 02:39:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63197404.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定