gradle - Gradle 子项目依赖项无法由需要它的项目解决
问题描述
我有以下项目结构:
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
└── test
模块1build.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"
}
模块build.gradle
2(取决于模块1)
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
看起来它只是在搜索使用 in而不是 inmodule1
声明的存储库的传递 deps 。module2
module1
有趣的是,如果我将依赖项更改module2
为:
dependencies {
compileClasspath project(':module1')
}
依赖关系已解决。然而,这意味着在运行时,module1
它不是类路径的一部分,因此运行应用程序仍然失败。
我怎样才能解决这个问题?
解决方案
问题是项目依赖项在依赖时不会泄漏其存储库位置。
解决方法是将存储库移动到 rootbuild.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 问题:
推荐阅读
- reactjs - 如何在使用 redux 的 React 组件中设置默认值?
- python - 如何在 python pandas 的索引中删除 NAN?
- django - 更新 Django 自定义视图的上下文
- laravel - Ubuntu 上的 Laravel 5.7“此 PHP 安装不提供 GD 库扩展。”
- java - 这种聚合在 Kafka 流中是如何工作的?
- git - 当存储库使用 LFS 时,如何在本地测试 gitlab 运行器脚本
- icecast - Icecast 更新标题元数据
- c# - 操作过滤器属性不运行
- javascript - Javascript 键码
- reactjs - reactjs router 4和redux的路由问题