我们有一个从命令行运行的工具。其中一个命令是-version。
在我们转换到nebula发布插件之前,版本在gradle.properties文件中,作为构建的一部分,我们将其复制到一个src/main/resources/version.txt文件中,该文件后来被工具读取以输出版本。
但是现在版本从未出现在签入git的文件中。相反,它只是在星云释放过程中才被知道。
我们希望在星云发布过程中获得该版本,并将其注入星云即将发布的jar中。例如,可以将其添加到清单中。
我们试图弄清楚如何做到这一点,但没有在网上看到任何例子,也没有在文档中看到有关它的任何内容。
发布于 2019-12-09 01:15:11
只需创建一个任务,缓存由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中在build输出中缓存/创建。上面的任务不将它与jar捆绑在一起。
希望这能让你知道该怎么做。

https://stackoverflow.com/questions/59228920
复制相似问题