kotlin - 如何在 gradle 项目中包含 github 存储库
问题描述
我正在尝试使用 gradle 创建一个库,并将这个库包含在另一个使用 gradle 和 github 链接的项目中。
我在 settings.gradle 中尝试这个:
sourceControl {
gitRepository(URI.create("https://github.com/fonnes/JsonKay.git")) {
producesModule("JsonKay:JsonKay")
}
}
这在 build.gradle 中:
implementation('JsonKay:JsonKay:1.0') {
version {
branch = 'main'
}
}
在尝试构建 gradle 时,我得到:Could not find any version that matches fonnes.JsonKay:JsonKay:{require 1.0; branch master}.
是我在本地项目或这个库中做错了什么吗?https://github.com/fonnes/JsonKay.git
编辑:我已将其从主分支更改为主分支。目前我无法在库中导入 Kotlin 文件。我确实在 intellij 的项目结构中看到了该库,但在依赖项列表中没有看到。
解决方案
首先,您没有分支master
,但是main
. 所以,这已经可以了:
implementation('fonnes.JsonKay:JsonKay:1.0') {
version {
branch = 'main'
}
}
但是,您应该定义版本 ( 1.0
) 或 a branch
,而不是同时定义两者。该版本1.0
将被解析为一个 Git 标签,并且定义branch
将指示 Gradle 签出相应的分支。
更好的:
implementation('fonnes.JsonKay:JsonKay') {
version {
branch = 'main'
}
}
或1.0
版本:
// settings.gradle.kts
sourceControl {
gitRepository(URI.create("https://github.com/fonnes/JsonKay.git")) {
producesModule("JsonKay:JsonKay")
}
}
// build.gradle.kts
implementation('JsonKay:JsonKay:1.0')
推荐阅读
- javascript - ReferenceError: 使用 jasmine 进行单元测试时未定义期望
- javascript - 如何将数据从 iram 传递给父级
- javascript - ReferenceError:在初始化之前无法访问“LCharacter”
- javascript - 如何将 async/await 与 Promises 结合使用?
- excel - 在数组VBA中重复偶数
- java - 如果语句没有被执行,即使它是真的
- python - 四方代码错误:TypeError:只能将 str(不是“元组”)连接到 str
- c# - 如何从另一个类中的索引器访问 Main() 方法中的元素?
- php - 如何在 php 中的 post 中找到 hashtag 和 tag 和 url?
- react-native - AutoHeightWebView 的 React-native Display 导致 Android 10 和 Android 11 崩溃