我正在尝试在现有的(2.0)插件的基础上创建一个新的maven (3.0.3)插件,并帮助以太获取一些依赖。
我尝试创建一个简单的测试来使用maven-plugin- test -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负载测试。有人有什么想法吗?
发布于 2021-02-08 04:48:20
7年后,我也遇到了同样的问题。
解决方案是添加maven-compat工件作为测试范围的依赖项,因为maven-plugin-testing-harness显然仍然依赖于旧的Maven2API。
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>[REQUIRED_MAVEN_VERSION_HERE]</version>
<scope>test</scope>
</dependency>https://stackoverflow.com/questions/14939341
复制相似问题