Maven多模块插件未执行

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

Maven multimodule mojo not executing

问题

我需要首先安装一个自定义插件(mojo),然后执行该目标。我希望这一切可以一气呵成,但是目前使用以下代码会导致构建错误。不确定我在下面的代码中是否走对了路,以便我可以首先安装插件,然后执行mojo内部的代码。

ParentProject:

<groupId>com.io</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Parent</name>
<description>ThisisParent</description>
<packaging>pom</packaging>
<modules>
    <module>Child1Plugin</module>
    <module>ChildFramework</module>
</modules>

Child1Plugin-pom.xml

<parent>
    <groupId>com.io</groupId>
    <artifactId>Parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>Child1Plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>Child</name>
<description>ThisisChild</description>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.4</version>
        </plugin>
        <plugin>
            <groupId>com.parent.module</groupId>
            <artifactId>ChildFramework</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <executions>
                <execution>
                    <goals>
                        <goal>mydata</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <scope>test</scope>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

ChildFramework-pom.xml

<parent>
    <groupId>com.io</groupId>
    <artifactId>Parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ChildFramework</artifactId>
<packaging>maven-plugin</packaging>
<name>Childtwo</name>
<description>Thisischildtwo</description>
<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>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.4</version>
        </plugin>
        <plugin>
            <groupId>com.io</groupId>
            <artifactId>ChildFramework</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <executions>
                <execution>
                    <goals>
                        <goal>mydata</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <scope>test</scope>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

下面的mojo位于ChildFramework模块的src/main/java文件夹中。

@Mojo(name = "mydata", defaultPhase = LifecyclePhase.COMPILE)
public class Feat extends AbstractMojo {   
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        System.out.println("%%%%%%%%%%%%%%%%%%%%%% MyMOJO");
    }
}
英文:

I need to install a custom plugin (mojo) first and then execute the goal. I would want this to happen in one go but as of now using below code i am getting build errors. Not sure if i'm going right in below code so that i can install plugin first and then code inside mojo would get executed.

ParentProject:

  &lt;groupId&gt;com.io&lt;/groupId&gt;
  &lt;artifactId&gt;Parent&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;Parent&lt;/name&gt;
  &lt;description&gt;ThisisParent&lt;/description&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
  &lt;modules&gt;
  	&lt;module&gt;Child1Plugin&lt;/module&gt;
  	&lt;module&gt;ChildFramework&lt;/module&gt;
  &lt;/modules&gt;

Child1Plugin-pom.xml

 &lt;parent&gt;
	&lt;groupId&gt;com.io&lt;/groupId&gt;
	&lt;artifactId&gt;Parent&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;name&gt;Child&lt;/name&gt;
&lt;description&gt;ThisisChild&lt;/description&gt;
&lt;build&gt;
	&lt;plugins&gt;
		&lt;plugin&gt;
			&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
			&lt;artifactId&gt;maven-plugin-plugin&lt;/artifactId&gt;
			&lt;version&gt;3.4&lt;/version&gt;
		&lt;/plugin&gt;
		&lt;plugin&gt;
			&lt;groupId&gt;com.parent.module&lt;/groupId&gt;
			&lt;artifactId&gt;ChildFramework&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;mydata&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;
&lt;/project&gt;

ChildFramework-pom.xml

    &lt;parent&gt;
		&lt;groupId&gt;com.io&lt;/groupId&gt;
		&lt;artifactId&gt;Parent&lt;/artifactId&gt;
		&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
	&lt;/parent&gt;
	&lt;artifactId&gt;ChildFramework&lt;/artifactId&gt;
	&lt;packaging&gt;maven-plugin&lt;/packaging&gt;
	&lt;name&gt;Childtwo&lt;/name&gt;
	&lt;description&gt;Thisischildtwo&lt;/description&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;/dependencies&gt;

	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-plugin-plugin&lt;/artifactId&gt;
				&lt;version&gt;3.4&lt;/version&gt;
			&lt;/plugin&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;com.io&lt;/groupId&gt;
				&lt;artifactId&gt;ChildFramework&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;mydata&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;

The below mojo is inside src/main/java folder of ChildFramework module.

@Mojo(name = &quot;mydata&quot;, defaultPhase = LifecyclePhase.COMPILE)
public class Feat extends AbstractMojo {   	
	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
        System.out.println(&quot;%%%%%%%%%%%%%%%%%%%%%% MyMOJO&quot;);
    }

答案1

得分: 1

ChildFramework 不能将自己用作插件(因为这会导致循环依赖)。我认为你需要的更改如下:

  • Child1Plugin:移除 ChildFramework 插件元素
  • ChildFramework:将 <packaging> 更改为 jar,并将插件的 <artifactId> 更改为 Child1Plugin
  • 将 mojo 代码从 ChildFramework 模块移动到 Child1Plugin 模块
英文:

ChildFramework can't use itself as a plugin (because that's a circular dependency). I think the changes you need are these:

  • Child1Plugin: remove the ChildFramework plugin element
  • ChildFramework: change &lt;packaging&gt; to jar and change the &lt;artifactId&gt; of the plugin to Child1Plugin
  • move the mojo code from the ChildFramework module to the Child1Plugin module

huangapple
  • 本文由 发表于 2020年7月31日 01:52:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63178682.html
匿名

发表评论

匿名网友

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

确定