Search code examples
eclipseeclipse-pluginxtexthamcrest

How do I get hamcrest-all into an Eclipse Xtext plugin project


I've been pulling my hair out for the better part of my weekend trying to get hacrest-all:1.3.0 or hamcrest:2.2.0 (prefered) into my freshly generated Xtext 21.1 plugin project.

As far as I can tell, the issue has to do with xtext.testing package depending on hamcrest.core:1.3.0, which is the only package in the orbit p2 repos. No problem, I will just add the jars manually, but as soon as I actually call any of the org.hamcres.Matchers.*, I get...

java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package

Well crap. I have tried just about every way imaginable to get this dependency hooked (ok well four, maven/jars x 1.3.0/2.2.0).

The strange thing is that I was doing this just fine on an older Xtext project.

But when I create a new Xtext project using the Wizard, I can no longer seem to hook up any useful hacrest matchers.

I just copied the same setup from the last project (with the jar file linked in build.properties), but nothing I can do in this fresh project seems to work.

Any ideas what I'm doing wrong here?

Full source can be found in org.agileware.natural.jbehave2.tests if it helps at all.

Thanks for your time!

UPDATE

I just realized the difference with the old project. It's not using maven!! So we have the source of the problem... is there a way to fix it without ditching maven builds? I would very much like to not be tied to Eclipse IDE for builds, please and thank you!


Solution

  • In addition to adding it to the build.properties, I also had to open the Project Settings and manually add the jar to the Java Build Path -> Libraries. While not strictly necessary for all jars, this allows one to specify the import order, giving the included jar first priority as expected.

    Update

    Here are the steps I took to get everything running smoothly.

    1. Grab hamcrest-2.2.jar and place them somewhere in a bundle.

    2. Set jars.extra.classpath in the build.properties in your test projects like so:

      jars.extra.classpath = platform:/plugin/org.example.mydsl.testing/lib/hamcrest-2.2.jar
      
    3. The MANIFEST.MF in your test projects should have Require-Bundle and Import-Package sections similar to this:

    Require-Bundle: org.example.mydsl,
     org.example.mydsl.testing,
     org.eclipse.xtext.testing,
     org.eclipse.xtext.xbase.testing,
     org.eclipse.xtext.xbase.lib;bundle-version="2.14.0"
    Import-Package: org.apache.commons.logging,
     org.apache.log4j,
     org.junit,
     org.junit.runner,
     org.junit.runner.manipulation,
     org.junit.runner.notification,
     org.junit.runners,
     org.junit.runners.model
    

    I may have possibly left out a step, but a fully working solution can be found in rlogiacco/Natural