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

烂漫一生 提交于 2019-12-22 18:03:04

问题


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?


回答1:


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.




回答2:


It seems to be a problem retrieving Groovy 2.5.6 from central. I am getting the same error trying to use Maven directly: mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get org.codehaus.groovy:groovy-all:jar:2.5.6

Looking at the server you can see that only docs and sources are available but not the JAR file. This is the case for all 2.5 releases of Groovy-all.

I assume the reason for this is that all 2.5 releases are just some sort of "meta artifact" without own code (therefore no JAR is available). The actual implementation is split into the following artifacts groovy-all depends on:

org.codehaus.groovy:groovy
org.codehaus.groovy:groovy-ant
org.codehaus.groovy:groovy-cli-commons
org.codehaus.groovy:groovy-cli-picocli
org.codehaus.groovy:groovy-console
org.codehaus.groovy:groovy-datetime
org.codehaus.groovy:groovy-docgenerator
org.codehaus.groovy:groovy-groovydoc
org.codehaus.groovy:groovy-groovysh
org.codehaus.groovy:groovy-jmx
org.codehaus.groovy:groovy-json
org.codehaus.groovy:groovy-jsr223
org.codehaus.groovy:groovy-macro
org.codehaus.groovy:groovy-nio
org.codehaus.groovy:groovy-servlet
org.codehaus.groovy:groovy-sql
org.codehaus.groovy:groovy-swing
org.codehaus.groovy:groovy-templates
org.codehaus.groovy:groovy-test
org.codehaus.groovy:groovy-test-junit5
org.codehaus.groovy:groovy-testng
org.codehaus.groovy:groovy-xml

Therefore for modifying your code you have to identify the groovy artifacts you really need and add them one by one to your code.




回答3:


I think that starting from 2.5 version there is no single jar https://issues.apache.org/jira/browse/GROOVY-8751



来源:https://stackoverflow.com/questions/55206829/how-to-upgrade-groovy-all-from-2-4-to-2-5-when-running-in-osgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!