takari / takari-plugin-testing-project

Maven Plugin Testing Framework
Eclipse Public License 1.0
27 stars 19 forks source link

Guice error when running a test #6

Closed gvlasov closed 9 years ago

gvlasov commented 9 years ago

When I run a test, there is this error log.

Here is the test I run: https://github.com/Suseika/git-version-insert-maven-plugin/blob/d9258cec2597a902c2ed850820496c263a38e5bd/src/test/java/org/tendiwa/maven/gitversioninsert/GitVersionInsertMojoTest.java

I'm using takari-plugin-testing version 2.6.0

Here is the error log:

java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.of(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/common/collect/ImmutableList;
    at com.google.inject.internal.Errors.<clinit>(Errors.java:644)
    at com.google.inject.internal.InternalInjectorCreator.<init>(InternalInjectorCreator.java:62)
    at com.google.inject.Guice.createInjector(Guice.java:94)
    at com.google.inject.Guice.createInjector(Guice.java:71)
    at com.google.inject.Guice.createInjector(Guice.java:61)
    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:477)
    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:203)
    at io.takari.maven.testing.Maven30xRuntime.<init>(Maven30xRuntime.java:106)
    at io.takari.maven.testing.Maven311Runtime.<init>(Maven311Runtime.java:26)
    at io.takari.maven.testing.Maven321Runtime.<init>(Maven321Runtime.java:39)
    at io.takari.maven.testing.Maven321Runtime.create(Maven321Runtime.java:35)
    at io.takari.maven.testing.TestMavenRuntime$3.newInstance(TestMavenRuntime.java:87)
    at io.takari.maven.testing.TestMavenRuntime.newMavenRuntime(TestMavenRuntime.java:200)
    at io.takari.maven.testing.TestMavenRuntime.access$1(TestMavenRuntime.java:197)
    at io.takari.maven.testing.TestMavenRuntime$6.evaluate(TestMavenRuntime.java:186)
    at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
ifedorenko commented 9 years ago

Several problems.

First, you need to use the same version of all maven core dependencies. This is not specific to plugin testing harness, but generally the right thing to do. In your case you have dependency on maven-plugin-api 2.0, maven-core 3.2.1 and maven-compat 3.0-alpha-2. I suggest using latest version of maven dependencies for compilation and unit testing (see below) and run basic integration tests with other versions of maven you want your plugin to be compatible with.

Second, there is a know unit test harness limitation I need to document somewhere. Unit test harness uses the same scope=test classpath to load maven core, plugin and plugin test classes. This means plugin and plugin tests must use the same versions of common dependencies as the version of maven core used during integration test. In your case the unit test is running with maven 3.2.1 (as specified in pom.xml), which uses guava 14.0.1, but the plugin depends on guava 18.0 (as specified in parent pom.xml). This results in unresolved method error you get.

The easiest solution is to change maven core dependency to 3.3.3, which uses the same guava 18 as specified in the parent pom.

If you absolutely must use plugin-specific version of guava (or any other dependency present in maven core), then you can't use unit test harness and must use integration test harness instead.

gvlasov commented 9 years ago

@ifedorenko Thanks, that was helpful.