如何使 Maven 解析器用于 Shrinkwrap 工作?
How to make Maven resolver for Shrinkwrap work?
我有这个代码:
@Deployment(name = "default")
public static WebArchive getTestArchive() {
File[] file = Maven.resolver().loadPomFromFile("../pom.xml")
.importCompileAndRuntimeDependencies()
.resolve("org.restlet.gae:org.restlet").withTransitivity().asFile();
System.out.println("FILE>>>>>>>>" + file.toString());
return ShrinkWrap.create(WebArchive.class, "simple.war")
.addClass(org.restlet.ext.servlet.ServerServlet.class)
.setWebXML("web.xml")
.addAsWebInfResource("appengine-web.xml")
.addAsWebInfResource("logging.properties");
}
但是当测试运行时它抛出这个错误:
Caused by: org.jboss.shrinkwrap.resolver.api.ResolutionException: Unable to get version for dependency specified by org.restlet.gae:org.restlet:compile, it was not provided in neither <dependencyManagement> nor <dependencies> sections.
at org.jboss.shrinkwrap.resolver.impl.maven.task.ResolveVersionFromMetadataTask.execute(ResolveVersionFromMetadataTask.java:91)
at org.jboss.shrinkwrap.resolver.impl.maven.PomEquippedResolveStageBaseImpl.resolveVersion(PomEquippedResolveStageBaseImpl.java:85)
at org.jboss.shrinkwrap.resolver.impl.maven.ResolveStageBaseImpl.resolveDependency(ResolveStageBaseImpl.java:189)
at org.jboss.shrinkwrap.resolver.impl.maven.ResolveStageBaseImpl.resolveDependency(ResolveStageBaseImpl.java:184)
at org.jboss.shrinkwrap.resolver.impl.maven.ResolveStageBaseImpl.resolve(ResolveStageBaseImpl.java:78)
at org.jboss.shrinkwrap.resolver.impl.maven.ResolveStageBaseImpl.resolve(ResolveStageBaseImpl.java:43)
... 58 more
我的目标是解决 POM 的所有依赖关系,以便(希望)Restlet arquillian 测试能够正常工作。
您的错误背后的原因似乎很明显。您的代码缺少 restlet 工件的版本号。
它应该看起来像:
File[] file = Maven.resolver().loadPomFromFile("../pom.xml")
.importCompileAndRuntimeDependencies()
.resolve("org.restlet.gae:org.restlet:2.3.0") // Notice version number
.withTransitivity().asFile();
或者您可以在 <dependencyManagement>
部分指定版本,但您的错误消息告诉您,您也忘记了它。
我有这个代码:
@Deployment(name = "default")
public static WebArchive getTestArchive() {
File[] file = Maven.resolver().loadPomFromFile("../pom.xml")
.importCompileAndRuntimeDependencies()
.resolve("org.restlet.gae:org.restlet").withTransitivity().asFile();
System.out.println("FILE>>>>>>>>" + file.toString());
return ShrinkWrap.create(WebArchive.class, "simple.war")
.addClass(org.restlet.ext.servlet.ServerServlet.class)
.setWebXML("web.xml")
.addAsWebInfResource("appengine-web.xml")
.addAsWebInfResource("logging.properties");
}
但是当测试运行时它抛出这个错误:
Caused by: org.jboss.shrinkwrap.resolver.api.ResolutionException: Unable to get version for dependency specified by org.restlet.gae:org.restlet:compile, it was not provided in neither <dependencyManagement> nor <dependencies> sections.
at org.jboss.shrinkwrap.resolver.impl.maven.task.ResolveVersionFromMetadataTask.execute(ResolveVersionFromMetadataTask.java:91)
at org.jboss.shrinkwrap.resolver.impl.maven.PomEquippedResolveStageBaseImpl.resolveVersion(PomEquippedResolveStageBaseImpl.java:85)
at org.jboss.shrinkwrap.resolver.impl.maven.ResolveStageBaseImpl.resolveDependency(ResolveStageBaseImpl.java:189)
at org.jboss.shrinkwrap.resolver.impl.maven.ResolveStageBaseImpl.resolveDependency(ResolveStageBaseImpl.java:184)
at org.jboss.shrinkwrap.resolver.impl.maven.ResolveStageBaseImpl.resolve(ResolveStageBaseImpl.java:78)
at org.jboss.shrinkwrap.resolver.impl.maven.ResolveStageBaseImpl.resolve(ResolveStageBaseImpl.java:43)
... 58 more
我的目标是解决 POM 的所有依赖关系,以便(希望)Restlet arquillian 测试能够正常工作。
您的错误背后的原因似乎很明显。您的代码缺少 restlet 工件的版本号。
它应该看起来像:
File[] file = Maven.resolver().loadPomFromFile("../pom.xml")
.importCompileAndRuntimeDependencies()
.resolve("org.restlet.gae:org.restlet:2.3.0") // Notice version number
.withTransitivity().asFile();
或者您可以在 <dependencyManagement>
部分指定版本,但您的错误消息告诉您,您也忘记了它。