在maven-plugin-testing-harness中注入DefaultRepositorySystem时出错

时间:2013-02-18 15:07:28

标签: maven maven-plugin aether

我正在尝试基于现有的(2.0)插件创建一个新的maven(3.0.3)插件,并促进以太网拾取一些依赖项。

我尝试使用maven-plugin-testing-harness(版本2.0.1)创建一个简单的测试来加载mojo,但是lookupMojo失败并带有guice异常:

1) Error injecting: org.sonatype.aether.impl.internal.DefaultRepositorySystem
at ClassRealm[plexus.core, parent: null]
at ClassRealm[plexus.core, parent: null]
while locating org.sonatype.aether.RepositorySystem
while locating org.codehaus.griffon.maven.plugin.MvnValidateMojo
at ClassRealm[plexus.core, parent: null]
while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=org.codehaus.griffon:griffon-maven-plugin:1.3.0-SNAPSHOT:validate)

这当然是因为我需要在某个时候引用存储库系统,但现在不需要:

@Component
private RepositorySystem repoSystem;

我已经尝试过(实际上已经开始使用)2.1版,但在AbstractMojoTestCase #setUp()方法中遇到了问题。

org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
  role: org.apache.maven.repository.RepositorySystem
roleHint:
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:247)

无论哪种方式,不确定我需要包括什么以及在哪里进行类似于食谱的香草mojo负载测试。有人有任何想法吗?

1 个答案:

答案 0 :(得分:0)

7 年后,我遇到了同样的问题。

解决方案是还添加 maven-compat 工件作为测试范围的依赖项,因为 maven-plugin-testing-harness 显然仍然依赖旧的 Maven 2 API。

<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-compat</artifactId>
    <version>[REQUIRED_MAVEN_VERSION_HERE]</version>
    <scope>test</scope>
</dependency>

感谢用户 smoke 的回答https://stackoverflow.com/a/16707144/5116073