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

Gradle构建报错:无法为Jar任务设置未知属性baseName

解决Gradle Jar任务baseName属性不存在的构建错误

问题原因

Gradle 7.0及以上版本中,Jar任务的baseName属性已被废弃并移除,取而代之的是archiveBaseName。你使用的Gradle 8.x版本不再支持baseName,因此构建时报错。

修复方案

修改build.gradle中的createJar任务,将baseName替换为archiveBaseName,同时可根据实际环境优化其他配置:

plugins {
    id 'java'
}

group 'regular-ghost-player'
version '1.0' // 建议设置有效版本号,避免manifest版本为空

sourceCompatibility = 17 // 匹配你的JDK17版本,若需兼容低版本可保留1.8

repositories {
    mavenCentral()
}

dependencies {
    testImplementation group: 'junit', name: 'junit', version: '4.12'
}

task createJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Ghost Project',
            'Implementation-Version': version,
            'Main-Class': 'myCode.GhostSkeleton'
    }
    archiveBaseName = 'winnerBot' // 替换原baseName属性
    destinationDirectory.set(file("$projectDir/"))
    from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

关键修改点

  • 核心修复:用archiveBaseName替代baseName,适配Gradle 7+的API变更
  • 可选优化:设置具体的version值,确保manifest中的版本信息有效
  • 可选优化:同步sourceCompatibility与JDK17版本,充分利用新版本特性

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 06:15:04