How to upgrade groovy-all from 2.4 to 2.5 when running in OSGi?

Johan :

I'm maintaining an open source library based partly on Groovy called Rest Assured. In the next version I'd like to upgrade the Groovy dependency from 2.4.x to 2.5.x. However when doing this I run into issues when running the OSGi tests. The tests are using Pax Exam they typically look something like this:

@RunWith(PaxExam.class)
public class XmlPathOSGiITest {

    @Configuration
    public static Option[] configure() {
        return new Option[]
                {
                        mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.hamcrest", "1.3_1"),
                        junitBundles(),
                        systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
                        systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),

                        /* Transitive dependencies needed in the Pax Exam container.
                        Some of these need to be wrapped because they are not available as OSGi bundles */
                        mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(),
                        wrappedBundle(mavenBundle().groupId("org.ccil.cowan.tagsoup").artifactId("tagsoup").versionAsInProject()),
                        wrappedBundle(mavenBundle("javax.xml.bind", "jaxb-api").versionAsInProject()),
                        wrappedBundle(mavenBundle("javax.activation", "activation").version("1.1.1")),
                        wrappedBundle(mavenBundle().groupId("org.codehaus.groovy").artifactId("groovy-all").version("2.5.6")),
                        wrappedBundle(mavenBundle("org.apache.httpcomponents", "httpclient").versionAsInProject()),
                        wrappedBundle(mavenBundle("org.apache.httpcomponents", "httpmime").versionAsInProject()),
                        wrappedBundle(mavenBundle("org.apache.httpcomponents", "httpcore").versionAsInProject()),

                        /* Rest Assured dependencies needed in the Pax Exam container to be able to execute the tests below */
                        mavenBundle("io.rest-assured", "json-path").versionAsInProject(),
                        mavenBundle("io.rest-assured", "xml-path").versionAsInProject(),
                        mavenBundle("io.rest-assured", "rest-assured").versionAsInProject(),
                        mavenBundle("io.rest-assured", "rest-assured-common").versionAsInProject()
                };
    }

    @Test
    public void getUUIDParsesAStringResultToUUID() {
        final String UUID_XML = "<some>\n" +
                "  <thing id=\"1\">db24eeeb-7fe5-41d3-8f06-986b793ecc91</thing>\n" +
                "  <thing id=\"2\">d69ded28-d75c-460f-9cbe-1412c60ed4cc</thing>\n" +
                "</some>";

        final UUID uuid = from(UUID_XML).getUUID("some.thing[0]");

        assertThat(uuid, Matchers.equalTo(UUID.fromString("db24eeeb-7fe5-41d3-8f06-986b793ecc91")));
    }
}

Running this test will cause an error:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.86 sec <<< FAILURE! - in io.restassured.test.osgi.XmlPathOSGiITest
getUUIDParsesAStringResultToUUID(io.restassured.test.osgi.XmlPathOSGiITest)  Time elapsed: 1.85 sec  <<< ERROR!
java.io.IOException: Error resolving artifact org.codehaus.groovy:groovy-all:jar:2.5.6: Could not find artifact org.codehaus.groovy:groovy-all:jar:2.5.6 in central (http://repo1.maven.org/maven2/)
        at org.ops4j.pax.url.mvn.internal.AetherBasedResolver.resolve(AetherBasedResolver.java:626)

The point of interest is probably this line:

wrappedBundle(mavenBundle().groupId("org.codehaus.groovy").artifactId("groovy-all").version("2.5.6")),

Everything was working fine when the Groovy was specified to use version 2.4.15. So my questions is:

How do I upgrade Groovy from 2.4 to 2.5 in an OSGi context when having depended on the groovy-all jar from 2.4 in past? And how do I reflect this in the test?

Steven Huypens :

It turns out that after choosing the correct artifacts, in this case groovy and groovy-json, you need Apache Aries SPI Fy as well.

mavenBundle().groupId("org.apache.aries.spifly").artifactId("org.apache.aries.spifly.dynamic.bundle").version("1.2.1")

If you don't add that bundle, the groovy-json OSGi Fragment bundle does not get RESOLVED, without any hints about the cause in the logging.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=143699&siteId=1