You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Grails 6.2.3升级后buildProperties未定义问题求助

解决Grails 6中buildProperties不存在的错误

问题原因

Grails 6(基于Gradle 7+)重构了构建系统,移除了旧版本(如Grails 5)中默认提供的buildProperties扩展,直接沿用旧配置会触发该错误。

替代方案

根据你原本用buildProperties实现的功能,选择对应方案:

1. 管理应用版本

如果只是设置应用版本,直接在build.gradle中定义项目版本即可:

version = '1.0.0'

应用内可通过grailsApplication.metadata.version获取该版本号。

2. 自定义构建属性

若需要定义更多自定义构建属性,在gradle.properties文件中添加:

appVersion=1.0.0
buildRevision=abc123

然后在build.gradle中通过project.属性名引用:

// 示例:在Jar包manifest中添加版本信息
tasks.withType(Jar) {
    manifest {
        attributes 'Implementation-Version': project.appVersion
    }
}

应用代码中可通过System.getProperty("appVersion")获取这些属性。

3. 生成构建信息文件

如果原本用buildProperties生成构建信息文件(如build-info.properties),可自定义Gradle任务实现:

task generateBuildInfo {
    doLast {
        def targetFile = file("src/main/resources/build-info.properties")
        targetFile.parentFile.mkdirs()
        targetFile.text = """
app.version=${version}
build.timestamp=${new Date().format('yyyy-MM-dd HH:mm:ss')}
build.number=${System.getenv('BUILD_NUMBER') ?: 'local'}
        """.trim()
    }
}
// 让资源处理任务依赖该生成任务
processResources.dependsOn(generateBuildInfo)

内容的提问来源于stack exchange,提问作者user1441429

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 00:22:10