Stephan Druskat
2017-07-20 14:12:34 UTC
Dear List,
I've managed to get JUnit 4.12 + Hamcrest 1.3 + Mockito 2.8.47 to work
in Eclipse so that when I add them as dependencies, the tests will run.
(The way I've done this is using the p2-maven-plugin
(https://github.com/reficio/p2-maven-plugin/) to bundle the following
artifacts from Maven Central into plugins/a feature and provie them via P2:
https://github.com/reficio/p2-maven-plugin/
- junit 4.12
- org.mockito.mockito-core 2.8.47
- org.hamcrest.all 1.3.0
)
Adding the plugins to my test fragment as dependencies makes the tests
run in Eclipse.
However, the Tycho build of the same fragment will fail with the
following messages:
java.lang.LinkageError: loader constraint violation: loader (instance of
org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously
initiated loading for a different type with name "org/hamcrest/Matcher"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at
org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:12)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
So it seems that some other plugin is loading the package
"org.hamcrest.Matcher" before this fragment does. This is probably due
to the import/export/partial import/partial export chaos surrounding the
JUnit/Hamcrest/Mockito setup.
Does anyone have an idea, or even better: a working example, of how to
get the three components work together both within the IDE (for quick
checks on whether tests run) and Tycho (for checks during the build?
Many thanks indeed!
Best
Stephan
I've managed to get JUnit 4.12 + Hamcrest 1.3 + Mockito 2.8.47 to work
in Eclipse so that when I add them as dependencies, the tests will run.
(The way I've done this is using the p2-maven-plugin
(https://github.com/reficio/p2-maven-plugin/) to bundle the following
artifacts from Maven Central into plugins/a feature and provie them via P2:
https://github.com/reficio/p2-maven-plugin/
- junit 4.12
- org.mockito.mockito-core 2.8.47
- org.hamcrest.all 1.3.0
)
Adding the plugins to my test fragment as dependencies makes the tests
run in Eclipse.
However, the Tycho build of the same fragment will fail with the
following messages:
java.lang.LinkageError: loader constraint violation: loader (instance of
org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously
initiated loading for a different type with name "org/hamcrest/Matcher"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at
org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:12)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
So it seems that some other plugin is loading the package
"org.hamcrest.Matcher" before this fragment does. This is probably due
to the import/export/partial import/partial export chaos surrounding the
JUnit/Hamcrest/Mockito setup.
Does anyone have an idea, or even better: a working example, of how to
get the three components work together both within the IDE (for quick
checks on whether tests run) and Tycho (for checks during the build?
Many thanks indeed!
Best
Stephan