我有以下项目结构:
example
├── build.gradle
├── module1
│ ├── build.gradle
│ └── main
│ ├── java
│ │ ├── module-info.java
│ │ └── com.example.module1
│ │ └── Example.java
│ └── resources
│ └── application.yml
└── module2
├── build.gradle
├── main
│ ├── java
│ │ ├── module-info.java
│ │ └── com.example.module2
│ │ └── Example2.java
└── testmodule1 build.gradle
repositories {
maven {
url 'http://download.osgeo.org/webdav/geotools/'
name 'Open Source Geospatial Foundation Repository'
}
maven {
url 'https://repo.boundlessgeo.com/main/'
name 'Boundless Maven Repository'
}
maven {
url 'http://repo.boundlessgeo.com/snapshot'
name 'Geotools SNAPSHOT repository'
mavenContent {
snapshotsOnly()
}
}
mavenCentral()
jcenter()
}
dependencies {
implementation "org.geotools:gt-main:$geotoolsVersion"
}module2 build.gradle (依赖于module1)
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation project(':module1')
}问题是,在解析module2的依赖关系时,它无法找到module1的传递依赖关系,因此我得到了以下错误:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':module2'.
> Could not resolve all files for configuration ':module2:runtimeClasspath'.
> Could not find org.geotools:gt-main:21.2.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/org/geotools/gt-main/21.2/gt-main-21.2.pom
- https://repo.maven.apache.org/maven2/org/geotools/gt-main/21.2/gt-main-21.2.jar
- https://jcenter.bintray.com/org/geotools/gt-main/21.2/gt-main-21.2.pom
- https://jcenter.bintray.com/org/geotools/gt-main/21.2/gt-main-21.2.jar
Required by:
project :module2 > project :module1看起来它只是使用在module1中声明的存储库来搜索module2的传递deps,而不是在module1中。
有趣的是,如果我将module2中的依赖项更改为:
dependencies {
compileClasspath project(':module1')
}依赖关系已解决。但是,这意味着在运行时,module1不是类路径的一部分,因此运行应用程序仍然会失败。
我该如何解决这个问题呢?
发布于 2019-07-17 16:00:44
问题是,项目依赖关系在依赖时不会泄漏它们的存储库位置。
修复方法是将存储库移动到根build.gradle中。类似于:
subprojects {
repositories {
//https://docs.geotools.org/latest/userguide/build/maven/repositories.html
maven {
url 'http://download.osgeo.org/webdav/geotools/'
name 'Open Source Geospatial Foundation Repository'
}
maven {
url 'https://repo.boundlessgeo.com/main/'
name 'Boundless Maven Repository'
}
}
}请参阅以下github问题:
https://stackoverflow.com/questions/57067670
复制相似问题