自定义 Maven 插件开发 - 尽管包含依赖项,但 getArtifacts 为空 [英] Custom Maven Plugin development - getArtifacts is empty though dependencies are included
问题描述
MavenProject.getArtifacts() 始终为空,但我能够看到 MavenProject.getDependencies() 返回所需的依赖项列表.
MavenProject.getArtifacts() is always empty, though I am able to see the MavenProject.getDependencies() returning the required list of dependencies.
我已经尝试将 ArtifactHandled 添加到 components.xml 并对其进行了适当的配置,但仍然没有解决方案
I have tried adding the ArtifactHandled to the components.xml and configured it appropriately but still no solution
components.xml 文件
components.xml file
<components>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>xyz</role-hint>
<implementation>
org.apache.maven.artifact.handler.DefaultArtifactHandler
</implementation>
<configuration>
<type>xyz</type>
<extension>xyz</extension>
<language>xyz</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>xyz</role-hint>
<implementation>
org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
</implementation>
<configuration>
<phases>
<compile>
com.xyz.maven.plugin:otx-maven-plugin:cmp
</compile>
<package>
com.xyz.maven.plugin:otx-maven-plugin:pkg
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.5.2:install
</install>
</phases>
</configuration>
</component>
</components>
依赖于 pom.xml
dependency in pom.xml
<dependencies>
<dependency>
<groupId>com.xyz.test.Project</groupId>
<artifactId>testProject</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>xyz</type>
<scope>compile</scope>
</dependency>
</dependencies>
我想知道如何将 getDependencies 转换为关联的 getArtifacts,因为这是编译器使用的
I would like to know how to transform the getDependencies into associated getArtifacts since that is what is used by the compiler
推荐答案
看来我需要在 @Mojo 注释中添加 requiresDependencyResolution 属性对于包装生命周期,我需要 requiresDependencyResolution = ResolutionScope.RUNTIME对于编译生命周期,我需要 requiresDependencyResolution = ResolutionScope.COMPILE
It seems I needed to add the requiresDependencyResolution attribute to the @Mojo annotation For packaging lifecycle I needed requiresDependencyResolution = ResolutionScope.RUNTIME For compile lifecycle I needed requiresDependencyResolution = ResolutionScope.COMPILE
示例:@Mojo(name = "myCompiler", defaultPhase = LifecyclePhase.COMPILE, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE )
Example: @Mojo(name = "myCompiler", defaultPhase = LifecyclePhase.COMPILE, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE )
这篇关于自定义 Maven 插件开发 - 尽管包含依赖项,但 getArtifacts 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!