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

Nie*_*sen 8 maven-plugin maven 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)
Run Code Online (Sandbox Code Playgroud)

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

@Component
private RepositorySystem repoSystem;
Run Code Online (Sandbox Code Playgroud)

我已经尝试过(实际上已经开始)版本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)
Run Code Online (Sandbox Code Playgroud)

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

Seb*_*hke 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>
Run Code Online (Sandbox Code Playgroud)

感谢用户Smoke的回答/sf/answers/1169500111/