英文:
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:
<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>
The below mojo is inside src/main/java folder of ChildFramework module.
@Mojo(name = "mydata", defaultPhase = LifecyclePhase.COMPILE)
public class Feat extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
System.out.println("%%%%%%%%%%%%%%%%%%%%%% MyMOJO");
}
答案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
<packaging>
tojar
and change the<artifactId>
of the plugin toChild1Plugin
- move the mojo code from the ChildFramework module to the Child1Plugin module
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论