我在使用gradle通过artifactory解决依赖关系时遇到问题。但我可以使用maven来解决这种依赖,所以我不确定我做错了什么。
maven构建文件是:
<dependencies>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>geoserver</artifactId>
<version>2.5.1</version>
<type>war</type>
</dependency>
</dependencies>
<repositories>
<repository>
<name>libs-releases</name>
<url>http://<artifactory-host>/artifactory/libs-releases</url>
</repository>
</repositories>
我可以确认maven会解决依赖关系:
$ mvn dependency:resolve
Downloading: http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.pom
Downloading: http://<artifactory-host>/artifactory/libs-releases/org/geoserver/web/2.5.1/web-2.5.1.pom
Downloading: http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.war
[INFO] The following files have been resolved:
[INFO] org.geoserver:geoserver:war:2.5.1:compile
我的gradle构建脚本是:
repositories {
mavenCentral()
maven { url 'http://<artifactory-host>/artifactory/libs-releases' }
}
dependencies {
compile 'org.geoserver:geoserver:2.5.1@war'
}
但gradle无法解决依赖关系:
$ gradle dependencies
:dependencies
compile - Compile classpath for source set 'main'.
\--- org.geoserver:geoserver:2.5.1 FAILED
我已经清理了本地存储库和缓存,以确保解析依赖关系。如果我打开调试输出,我可以看到有对POM文件的HTTP请求,但是没有对WAR文件的HTTP请求。
[DEBUG] [org.apache.http.impl.conn.DefaultClientConnection] Sending request: HEAD /artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.pom HTTP/1.1
[DEBUG] [org.apache.http.impl.conn.DefaultClientConnection] Receiving response: HTTP/1.1 200 OK
我可以直接下载POM和WAR文件,因此不存在工件或代理问题或身份验证问题:
$ wget http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.pom
`geoserver-2.5.1.pom' saved [32283/32283]
$ wget http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.war
`geoserver-2.5.1.war' saved [60164745/60164745]
我看不出我在这里做错了什么。它可能很简单?
编辑#1 我在artifactory中添加了对JAR文件的依赖,该文件无错误地解析。然后我在artifactory中添加了另一个WAR文件的依赖项,它也解决了没有错误。但由于某种原因,原始地理服务器WAR依赖关系在使用maven时解决,但在使用gradle时则不会解决。
编辑#2 使用maven版本时,我看到以下警告:
[WARNING] The POM for org.geoserver:geoserver:war:2.5.1 is invalid, transitive dependencies (if any) will not be available: 2 problems were encountered while building the effective model for org.geoserver:geoserver:2.5.1
[ERROR] Invalid packaging for parent POM org.geoserver:geoserver:2.5.1, must be "pom" but is "war" @
[FATAL] The parents form a cycle: org.geoserver:geoserver:2.5.1 -> org.geoserver:web:2.5.1 -> org.geoserver:geoserver:2.5.1 @
查看地理服务器2.5.1源代码:
org.geoserver:geoserver
(WAR)有父org.geoserver:web
(POM)org.geoserver:web
(POM)有父org.geoserver:geoserver
(WAR)因此存在循环依赖关系,org.geoserver:web
的父级具有非POM包装。
但是maven继续下载WAR文件,尽管这个'致命'错误:
Downloaded: http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.war (58755 KB at 8601.2 KB/sec)
也许gradle对这个问题更严格?
编辑#3 我更改了依赖项以排除org.geoserver:geoserver
上的传递依赖项:
dependencies {
compile('org.geoserver:geoserver:2.5.1@war') {
transitive = false
}
...
但是当我运行$ gradle dependencies
时,依赖关系仍无法解决。
使用此依赖关系运行任务时出现堆栈溢出错误:
$ gradle bundleArtifacts
:bundleArtifacts
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> Could not resolve org.geoserver:geoserver:2.5.1.
Required by:
<my-project>:1.0-SNAPSHOT
> Could not resolve org.geoserver:geoserver:2.5.1.
> Could not parse POM http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.pom
> Could not resolve org.geoserver:web:2.5.1.
> Could not parse POM http://<artifactory-host>/artifactory/libs-releases/org/geoserver/web/2.5.1/web-2.5.1.pom
> Could not resolve org.geoserver:geoserver:2.5.1.
...
这表明gradle没有考虑传递依赖,因为它不能解析POM文件,因为它存在循环依赖。
我认为这里唯一的解决方案是创建一个单独的工件(例如ZIP文件),其中包含org.geoserver:geoserver:2.5.1
WAR工件,添加对该ZIP文件的依赖关系,并创建一个提取内容的任务该ZIP文件到目标目录。
答案 0 :(得分:3)
看起来您正在使用导致此问题的修改后的pom文件
原始org.geoserver:geoserver模块的包类型是pom,它没有父模块。这是整个地理服务器项目的父pom,不应该用作依赖项
org.geoserver:web也是pom类型,并且作为所有Web相关模块的父级
查看geoserver Artifactory server,我找不到任何名为geoserver-x.x.x.war
的工件。似乎有人部署了web archive(战争)地理服务器的分布并修改了org.geoserver:geoserver
的原始pom文件,因此可以解决它。
如果你想继续解决这场战争,我建议为它创建一个新的专用.pom文件,它不会与地理服务器冲突(使用新的groupId / artifactId)。