gradle - 在 nebula/gradle 中,如何将正在发布的版本注入正在发布的 jar 中?
问题描述
我们有一个从命令行运行的工具。命令之一是-version。
在我们转换为 nebula 发布插件之前,版本位于 gradle.properties 文件中,作为构建的一部分,我们将其从那里复制到 src/main/resources/version.txt 文件中,该文件后来被工具读取输出版本。
但是现在该版本永远不会在签入 git 的文件中。相反,它只有在星云释放过程中才知道。
我们想在 nebula 发布过程中获取那个版本,并注入到 nebula 即将发布的 jar 中。例如,它可以添加到清单中。
我们试图弄清楚如何做到这一点,但在网上看不到任何示例,文档中也没有任何相关内容。
解决方案
只需创建一个缓存 Nebula 动态推断的版本的任务。
由于您最初复制/创建src/main/resources/version.txt
,我们将使用该模型我们的任务。
假设一个简单/标准的 Java 项目,使用Kotlin DSL:
val cacheNebulaVersion by tasks.registering {
mustRunAfter(tasks.named("release"))
doLast {
val sourceSets = project.extensions.getByName("sourceSets") as SourceSetContainer
sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).output.resourcesDir?.let {
// If there are not existing resources in your project then you must create
// the resources dir otherwise a FileNotFoundException will be thrown.
if (!it.exists()) {
it.mkdirs()
}
File(it, "version.txt").printWriter().use { out ->
out.println(project.version)
}
}
}
}
当我调用./gradlew clean build snapshot cacheNebulaVersion
时,Nebula 生成的版本src/main/resources/version.txt
在构建输出中被缓存/创建。上面的任务没有将它与 jar 捆绑在一起。
希望这能让你知道该怎么做。
推荐阅读
- java - 如果发生异常,如何打印mysql错误代码号,在spring core java中使用Jdbctemplate
- microsoft-graph-api - 从团队(组)成员中删除特定文件(驱动器项)的权限
- soa - 使用 php 创建面向启动服务架构的步骤
- android - 使用 Intent.createChooser 传递额外内容
- react-native - undefined 不是 TouchableOpacity onPress 中的函数
- kubernetes - kubernetes rbac 授权层似乎给出了不正确的结果
- ruby-on-rails - 无法理解使用带有 graphql-ruby gem 的 ActionCable 的 GraphQL 订阅
- c# - Visual Basic 语法错误。在页面指令中
- html - Bootstrap 4 - 我怎样才能适应列的内容大小?
- tensorflow - 如何使用 Tensorflow 的 Dataset API 在 Keras 中进行预测