Java maven插件组件注入空
我正在尝试编写自己的自定义maven插件,它扩展了AbstractDependencyMojo 问题是,在我的插件的代码执行过程中,所有AbstractDependencyMojo组件都是空的Java maven插件组件注入空,java,maven,plugins,components,pom.xml,Java,Maven,Plugins,Components,Pom.xml,我正在尝试编写自己的自定义maven插件,它扩展了AbstractDependencyMojo 问题是,在我的插件的代码执行过程中,所有AbstractDependencyMojo组件都是空的 @goal generate-dependencies @phase install @requiresProject false 请参阅下面的代码,重写方法execute() public void execute()引发MojoExecutionException异常{ 列表依赖项=proj
@goal generate-dependencies
@phase install
@requiresProject false
请参阅下面的代码,重写方法execute()
public void execute()引发MojoExecutionException异常{
列表依赖项=project.getModel().getDependencies();
for(依赖项:依赖项){
试一试{
工件a=factory.createArtifact(dependency.getGroupId()、dependency.getArtifactId()、dependency.getVersion()、dependency.getScope()、dependency.getType());
resolver.resolve(a,remoteRepos,getLocal());
}
捕获(工件解析异常e){
抛出新的MojoExecutionException(“隐式工件解析失败”,e);
}
捕获(artifactnotfounde异常){
//无所事事
}
}
调试时,project为null,factory为null,那么一切都是..null
显然,由于某些原因,组件注入根本不起作用,我不明白为什么
插件的调用方式如下:
<plugin>
<groupId>com.me.framework</groupId>
<artifactId>plugin-dependency-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<id>plugin-dependencies</id>
<phase>install</phase>
<goals>
<goal>generate-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
com.me.framework
插件依赖插件
0.0.1-快照
插件依赖项
安装
生成依赖项
你知道吗?谢谢
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.me.framework</groupId>
<artifactId>plugin-dependency-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model-builder</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<type>maven-plugin</type>
<version>2.5.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<versionRange>[3.2,)</versionRange>
<goals>
<goal>descriptor</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
4.0.0
com.me.framework
插件依赖插件
0.0.1-快照
maven插件
org.apache.maven
maven模型生成器
3.0.4
org.apache.maven
maven插件api
2
org.apache.maven
马文项目
2.2.1
org.apache.maven.plugin-tools
maven插件注释
3.1
org.apache.maven.plugins
maven依赖插件
maven插件
2.5.1
org.eclipse.m2e
生命周期映射
1.0.0
org.apache.maven.plugins
maven插件
[3.2,)
描述符
调用插件pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>TheArtifact</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>clean-generated-sources</id>
<phase>clean</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<!-- Package project as artifact (for apidoc) -->
<execution>
<id>package-project</id>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.me.framework</groupId>
<artifactId>plugin-dependency-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<id>plugin-dependencies</id>
<phase>install</phase>
<goals>
<goal>generate-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Install project resources as artifact (for apidoc) -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>install-project</id>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
4.0.0
艺术品
org.apache.commons
commons-lang3
maven清洁插件
清洁能源
清洁的
org.apache.maven.plugins
maven antrun插件
一揽子工程
准备包装
com.me.framework
插件依赖插件
0.0.1-快照
插件依赖项
安装
生成依赖项
org.codehaus.mojo
构建助手maven插件
安装项目
准备包装
首先,基于文档的标记已经过时,最好使用@Mojo注解来提供所有插件的详细信息:
@Mojo(
name = "generate-dependencies",
defaultPhase = LifecyclePhase.INSTALL,
requiresDependencyResolution = ResolutionScope.COMPILE
// ...
)
其次,我会检查
@requireproject
是否设置为false
,并尝试设置为true
,这也可能是原因。首先,基于文档的标记已经过时,最好使用@Mojo注释来提供所有插件细节:
@Mojo(
name = "generate-dependencies",
defaultPhase = LifecyclePhase.INSTALL,
requiresDependencyResolution = ResolutionScope.COMPILE
// ...
)
其次,我会检查
@requireproject
是否设置为false
,并尝试将其设置为true
,这也可能是原因。您可以发布整个MOJO而不是短片段吗?您发布了POM,但没有发布完整的Java类。您也可以发布吗?您只能编写一个从AbstractMojo
AbstractDependencyMojo
来自另一个插件…因此您可能需要使用此插件并增强实现。您可以发布整个MOJO而不是短片段吗?您发布了POM,但没有发布完整的Java类。您也可以发布吗?您只能编写一个扩展自Abstrac的插件tMojo
AbstractDependencyMojo
来自另一个插件…因此您可能需要使用此插件并增强实现..这是否适用于Maven 2,就像他们显然正在使用的那样?这是否适用于Maven 2,就像他们显然正在使用的那样?