Hi all,

When switching from Maven 3.0.x to 3.1.x some of our projects where not able to 
execute anymore due to a problem with MavenEmbedder. Both projects are command 
line based, no Maven plugin around it.

I think the most important part of the stack trace is this:

37) No implementation for 
java.util.Set<org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory> 
was bound.
  while locating 
java.util.Set<org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory>
    for parameter 0 at 
org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider.<init>(Unknown
...
37 errors
      role: org.apache.maven.execution.MavenExecutionRequestPopulator
  roleHint:
    at com.google.inject.internal.InjectorImpl$3.get(InjectorImpl.java:974)
    at org.eclipse.sisu.inject.LazyBeanEntry.getValue(LazyBeanEntry.java:82)
    at org.eclipse.sisu.plexus.LazyPlexusBean.getValue(LazyPlexusBean.java:51)
    at 
org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:260)
    at 
org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:252)
    at 
org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:246)
    at hudson.maven.MavenEmbedder.lookup(MavenEmbedder.java:567)
    at 
hudson.maven.MavenEmbedder.buildMavenExecutionRequest(MavenEmbedder.java:157)
    at hudson.maven.MavenEmbedder.<init>(MavenEmbedder.java:120)
    at hudson.maven.MavenEmbedder.<init>(MavenEmbedder.java:109)
    at hudson.maven.MavenEmbedder.<init>(MavenEmbedder.java:136)
    at test.embedder.AppTest.testLookup(AppTest.java:57)

I know this problem came when I changed my aether-dependencies from 
'org.sonatype.aether' to 'org.eclipse.aether' in order to work with Maven 3.1.x.

Fortunately this can be reproduced with a simple project which can be found 
here: https://dl.dropboxusercontent.com/u/86229859/embedder-test.tgz

Usage of the MavenEmbedder looks like this:

package test.embedder;
import hudson.maven.MavenEmbedder;
import hudson.maven.MavenEmbedderException;
import hudson.maven.MavenRequest;
import java.io.File;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.project.MavenProject;

public class App {
    private static final ClassLoader                mavenClassLoader = 
App.class.getClassLoader();
    private static final ThreadLocal<MavenEmbedder> embedder         = new 
ThreadLocal<MavenEmbedder>() {

                     @Override
                     protected MavenEmbedder initialValue() {
                         try {
                             MavenRequest req = new MavenRequest();
                             
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1);
                             return new MavenEmbedder(mavenClassLoader, req);
                         } catch (MavenEmbedderException e) {
                             throw new RuntimeException(
                                     "Error creating MavenEmbedder", e);
                         }
                     }
                 };

    public static MavenProject getMavenProject(File pomFile) {
        try {
            return embedder.get().readProject(pomFile);
        } catch (Exception e) {
            throw new RuntimeException("Error parsing POM at " + pomFile, e);
        }
    }
}

This unit test will then trigger the error:

package test.embedder;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class AppTest {
    private static File mvnUtilFolder = null;
    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        mvnUtilFolder = 
FileUtils.toFile(AppTest.class.getClassLoader().getResource("mvnUtil"));
    }

    @Test
    public void testGetMavenProject() {
        File mvnPom = new File(mvnUtilFolder.getAbsolutePath() + "/pom.xml");
        MavenProject mvnProject = App.getMavenProject(mvnPom);
        assertNotNull(mvnProject);
        assertEquals("3.5.2", mvnProject.getVersion());
    }
}

For me all this looks like a 'simple' classloader issue when Guice tries to 
load the classes (e.g.:  
org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory) but can't find 
them.

I've googled presumably all the places dealing with problems when switching 
from 3.0.x to 3.1.x and tried a lot of things without success. In particular:

* fixed all versions of plugins as described here: 
https://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound
* changed dependencies to Ather as described here: http://eclipse.org/aether
* basically I implemented things the way they are done in the lib-jenkins 
implementation itself here: 
https://github.com/jenkinsci/lib-jenkins-maven-embedder/blob/master/src/test/java/hudson/maven/TestMavenEmbedderSimpleProject.java
* tried to deal with different versions of validation level 
'req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1)'
* tried myriads of different POM configurations (dependencies, versions)

But actually this error persists (also when building with 3.0.x). So maybe 
anyone can point me to the right direction? I've dealt with this problem too 
long now and maybe I got blind for new approaches. Thanks in advance!

Bernd

Reply via email to