Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven plugin development - how to ensure building for Maven 3.0.x instead of 3.1.x?

I'm trying to develop a custom Maven plugin. I'm currently running into this problem when I execute my unit tests: java.lang.NoClassDefFoundError: org.eclipse.aether.RepositorySystemSession Stack trace is below:

initializationError(com.mycompany.MyPluginTest)  Time elapsed: 0 sec  (TestSuite.java:132)
    at org.junit.internal.runners.JUnit38ClassRunner.(JUnit38ClassRunner.java:72)
    at org.junit.internal.builders.JUnit3Builder.runnerForClass(JUnit3Builder.java:11)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:262)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.lang.ClassNotFoundException: org.eclipse.aether.RepositorySystemSession
    at java.net.URLClassLoader.findClass(URLClassLoader.java:423)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:660)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:346)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:626)
    at java.lang.J9VMInternals.verifyImpl(Native Method)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:72)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:70)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:134)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:44)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:516)
    at junit.framework.TestSuite.createTest(TestSuite.java:63)
    at junit.framework.TestSuite.addTestMethod(TestSuite.java:310)
    at junit.framework.TestSuite.addTestsFromTestCase(TestSuite.java:153)
    at junit.framework.TestSuite.(TestSuite.java:132)
    at org.junit.internal.runners.JUnit38ClassRunner.(JUnit38ClassRunner.java:72)
    at org.junit.internal.builders.JUnit3Builder.runnerForClass(JUnit3Builder.java:11)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:262)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

From my research, this can happen when building for Maven 3.1.x because Maven switched from the sonatype aether implementation to the eclipse implementation.

I am trying to build my plugin for Eclipse 3.0.4, since that's what's installed on all our workstations. I'm assuming that I'm seeing this error because one of my dependencies is a Maven 3.1.x dependency, although I'm not sure which one. Does anyone know which dependency I should correct?

Also, does anyone know if it's possible to build a plugin that will work for Maven 3.0.x and 3.1.x? I'd rather not have to go through all this again some day in the future when we move to a newer version of Maven.

The dependencies in my POM look like this:

<dependencies>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>3.0.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugin-tools</groupId>
        <artifactId>maven-plugin-annotations</artifactId>
        <version>3.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugin-tools</groupId>
        <artifactId>maven-plugin-tools-api</artifactId>
        <version>3.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugin-testing</groupId>
        <artifactId>maven-plugin-testing-harness</artifactId>
        <version>3.0.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-compat</artifactId>
        <version>3.0.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-model</artifactId>
        <version>3.0.4</version>
    </dependency>
</dependencies>
like image 337
FrustratedWithFormsDesigner Avatar asked Mar 10 '14 20:03

FrustratedWithFormsDesigner


People also ask

What are the correct type of Maven plugins?

Introduction. In Maven, there are two kinds of plugins, build and reporting: Build plugins are executed during the build and configured in the <build/> element. Reporting plugins are executed during the site generation and configured in the <reporting/> element.

Which Maven plugin do we use when we create a Maven project?

For example, to compile your project maven uses maven-compiler-plugin , to run tests - maven-surefire-plugin and so on. Dependency in terms of maven is a packaged piece of classes that your project depends on. It can be jar, war etc.

Which Maven plug in creates the project structure?

The correct answer to the question “Which Maven plugin creates the project structure” is, option (d). archetype. And all the other Maven plugin creates the project structure. If you are interested in learning Maven, look into the following video on Maven Tutorial for Beginners and get started.

What is the latest version of Maven?

Apache Maven 3.8.6 is the latest release and recommended version for all users.


1 Answers

Ok, so I think I figured out the issue with aether: it appears to depend on which version of maven-plugin-testing-harness is being used. Version <= 2.1 seems to use sonatype aether. Using this set of dependencies resolves the aether problem:

    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-artifact</artifactId>
        <version>3.0.5</version>
    </dependency>

    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-compat</artifactId>
        <version>3.0.5</version>
    </dependency>

    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>3.0.5</version>
    </dependency>

    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
    </dependency> 

    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-core</artifactId>
        <version>3.0.5</version>
    </dependency>  

    <dependency>
        <groupId>org.apache.maven.plugin-tools</groupId>
        <artifactId>maven-plugin-annotations</artifactId>
        <version>3.1</version>
    </dependency>
    <dependency>
        <!-- version 2.1 uses sonatype aether. anything after 2.1 uses eclipse aether. -->
        <groupId>org.apache.maven.plugin-testing</groupId>
        <artifactId>maven-plugin-testing-harness</artifactId>
        <scope>test</scope>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
like image 184
FrustratedWithFormsDesigner Avatar answered Nov 16 '22 00:11

FrustratedWithFormsDesigner