gpt4 book ai didi

gradle - 使用Gradle构建项目时如何获取实现版本

转载 作者:行者123 更新时间:2023-12-03 03:05:38 24 4
gpt4 key购买 nike

当使用 Maven 构建项目时,可以获得类似 this 的实现版本.有可能用 Gradle 做到这一点吗?

我的应用程序从 Maven 迁移到了 Gradle。通过 Maven 构建,我能够显示应用程序版本,如 Application vX.X.X,其中 X.X.X 是从实现版本中检索的。 Gradle 有可能吗?
基本上我希望那个版本是自动解析的。

最佳答案

jar {
manifest {
attributes('Main-Class': 'Your main class',
'Implementation-Title': 'Your title',
'Implementation-Version': 'You version')
}
}

或者如果你使用 shadowJar

shadowJar {
manifest {
attributes 'Main-Class': 'Your main class'
attributes 'Implementation-Title': 'Your title'
attributes 'Implementation-Version': 'You version'
}
}

然后在 java 源中你可以使用:

getClass().getPackage().getImplementationVersion()
getClass().getPackage().getImplementationTitle()

在 Gradle 文档中查看更多信息:https://docs.gradle.org/current/userguide/java_plugin.html#sub:manifest

关于gradle - 使用Gradle构建项目时如何获取实现版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21499341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com