我正在维护一个部分基于Groovy的名为Rest Assured的开源库。在下一个版本中,我想将Groovy依赖项从2.4.x升级到2.5.x。但是,这样做时,在运行OSGi测试时遇到了问题。测试使用的是Pax Exam,它们通常看起来像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")));
}
}
运行此测试将导致错误:
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)
兴趣点可能是这条线:
wrappedBundle(mavenBundle().groupId("org.codehaus.groovy").artifactId("groovy-all").version("2.5.6")),
当指定Groovy使用version
2.4.15时,一切工作正常。所以我的问题是:
过去依靠2.4的groovy-all
jar时,如何在OSGi上下文中将Groovy从2.4升级到2.5?我该如何在测试中体现这一点?
答案 0 :(得分:1)
从中央检索Groovy 2.5.6似乎是一个问题。我在尝试直接使用Maven时遇到了相同的错误:mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get org.codehaus.groovy:groovy-all:jar:2.5.6
查看server,您将看到仅文档和源可用,而JAR文件不可用。 Groovy-all的所有2.5发行版都是这种情况。
我认为这样做的原因是所有2.5版本都是某种“元工件”,没有自己的代码(因此没有JAR可用)。实际的实现分为以下几种groovy-所有依赖于:
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
因此,要修改代码,您必须确定您真正需要的常规工件,并将它们逐个添加到您的代码中。
答案 1 :(得分:1)
我认为从2.5版本开始,没有单个jar https://issues.apache.org/jira/browse/GROOVY-8751
答案 2 :(得分:1)
事实证明,在选择了正确的工件(在这种情况下为groovy和groovy-json)之后,您还需要Apache Aries SPI Fy。
mavenBundle().groupId("org.apache.aries.spifly").artifactId("org.apache.aries.spifly.dynamic.bundle").version("1.2.1")
如果您不添加该捆绑包,那么groovy-json OSGi Fragment捆绑包将无法得到解决,而在日志记录中也没有任何有关原因的提示。