Вопрос

I am trying to create a new maven (3.0.3) plugin based on an existing (2.0) plugin, and facilitating aether to pickup some dependencies.

I tried to create a simple test to load the mojo using the maven-plugin-testing-harness (version 2.0.1), but lookupMojo fails with a guice exception:

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)

This of course is because I need to reference the repository system at some point, but not right now:

@Component
private RepositorySystem repoSystem;

I have tried (actually started with) version 2.1, but got the problem in the AbstractMojoTestCase#setUp() method.

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)

Either way, Not sure what I need to include and where to do a vanilla mojo load test similar to the cookbook. Anybody got any ideas?

Это было полезно?

Решение

7 years later and I am hitting the same issue.

The solution is to also add the maven-compat artifact as test scoped dependency as the maven-plugin-testing-harness is apparently still relying on the old Maven 2 API.

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

Kudos to user smoke for his answer here https://stackoverflow.com/a/16707144/5116073

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top