只需创建一个缓存 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 捆绑在一起。
希望这能让你知道该怎么做。
![在此处输入图像描述](https://i.stack.imgur.com/AnGyT.png)