155*_*358 2 intellij-idea kotlin build.gradle
我想在我在 build.gradle 中设置的项目中获取我的项目版本。有没有什么方法可以在我的项目中获取版本,因为我需要在我的软件中显示版本并用于比较更新信息,这样我每次发布更新时都不需要更改两次。有什么办法可以做到吗?
group 'ProjectName.group'
version "ProjectVersion"
Run Code Online (Sandbox Code Playgroud)
您通常通过加载属性文件并配置 gradle 来过滤processResources任务中的属性文件来实现。
例子:
构建.gradle:
version = '1.5.0'
processResources {
def properties = ['version': project.version]
inputs.properties(properties)
filesMatching('version.properties') {
expand(properties)
}
}
Run Code Online (Sandbox Code Playgroud)
version.properties:
version=${version}
Run Code Online (Sandbox Code Playgroud)
应用程序.java:
public static void main(String[] args) throws IOException {
Properties properties = new Properties();
properties.load(App.class.getResourceAsStream("/version.properties"));
System.out.println(properties.getProperty("version"));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
676 次 |
| 最近记录: |