Can a maven mojo relying on Aether be compatible w

2019-03-26 07:17发布

The 3.1.0 release of Maven relies on Eclipse Aether (org.eclipse.aether) instead of Sonatype Aether (org.sonatype.aether). This seems to break compatibility for plugins relying on Sonatype aether : try running such plugins and you'll run into :

java.lang.NoClassDefFoundError: org/sonatype/aether/*
Caused by: java.lang.ClassNotFoundException: org.sonatype.aether.*

As documented in https://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound

Now, is it possible to make a mojo relying on aether classes (such as org.sonatype.aether.RepositorySystemSession) run both with Maven 3.0.x and Maven 3.1.x ?

Or do I have to release two versions of the same plugin, one for 3.0.x and one for 3.1.x ? Putting enforcer rules like this :

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.3</version>
    <executions>
      <execution>
        <id>enforce-maven</id>
        <goals>
          <goal>enforce</goal>
        </goals>
        <configuration>
          <rules>
            <requireMavenVersion>
              <version>[3.0,3.1)</version>
            </requireMavenVersion>
          </rules>
        </configuration>
      </execution>
    </executions>
  </plugin>

I already posted the question on Maven developers mailing list, but no answer so far...

2条回答
Ridiculous、
2楼-- · 2019-03-26 07:56

Most of these plugins depend on the Maven Dependency Tree, which is capable to collect the right set of dependencies no matter the Maven Version. Version 2.1 was released to support Eclipse Aether next to Sonatype Aether If your plugin can use this component, you should be save.

查看更多
Viruses.
3楼-- · 2019-03-26 08:07

Very good question! I am using the maven indexer to look up some artifacts. I am programmatically downloading the maven index from central and running queries on it. This is my method:

public IteratorSearchResponse executeGroupArtifactSearch(String group, String artifact) throws Exception {
        Query groupIdQ     = indexer.constructQuery( MAVEN.GROUP_ID,    new SourcedSearchExpression( group ) );
        Query artifactIdQ  = indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( artifact ) );
        BooleanQuery query = new BooleanQuery();
        query.add( groupIdQ   , Occur.MUST );
        query.add( artifactIdQ, Occur.MUST );
        query.add( indexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression( Field.NOT_PRESENT ) ), Occur.MUST_NOT );
        IteratorSearchRequest  request  = new IteratorSearchRequest( query, Collections.singletonList( centralContext ), null );
        IteratorSearchResponse response = indexer.searchIterator( request );
        return response;
    }

Since I updated to maven 3.1.0 and org.eclipse.aether I am getting this Exception:

Caused by: java.lang.ClassNotFoundException: org.sonatype.aether.version.InvalidVersionSpecificationException
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    ... 30 more

It seems that the 3.1.0 Maven Indexer still has some dependencies to org.sonatyep.aether. Curious enough that I get this Exception because "org.sonatype.aether.version.InvalidVersionSpecificationException" is still part of the project.

So how do I resolve this?

查看更多
登录 后发表回答