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

清理Gradle缓存后Liferay Workspace编译失败求助

问题:清理Gradle缓存后Liferay Workspace项目无法编译,报错找不到DownloadCommand类

清理电脑所有Gradle缓存后,执行./gradlew build时出现以下错误:

  • Where:
    Settings file 'src/liferay/settings.gradle' line: 20

  • What went wrong:
    A problem occurred evaluating settings 'liferay'.

Failed to apply plugin 'com.liferay.workspace'.
Could not create an instance of type com.liferay.gradle.plugins.workspace.WorkspaceExtension.
com/liferay/portal/tools/bundle/support/commands/DownloadCommand

项目的settings.gradle配置如下:

buildscript {
    dependencies {
        classpath group: "biz.aQute.bnd", name: "biz.aQute.bnd", version: "5.2.0"
        classpath(group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "3.4.48") {
            exclude group: "biz.aQute.bnd", module: "biz.aQute.bnd"
        }
        classpath group: "net.saliman", name: "gradle-properties-plugin", version: "1.4.6"
    }

}

apply plugin: "net.saliman.properties"

apply plugin: "com.liferay.workspace"

Gradle版本信息:

------------------------------------------------------------
Gradle 6.6.1
------------------------------------------------------------

Build time:   2020-08-25 16:29:12 UTC
Revision:     f2d1fb54a951d8b11d25748e4711bec8d128d7e3

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          11.0.20 (Azul Systems, Inc. 11.0.20+8-LTS)
OS:           Linux 6.4.7-200.fc38.x86_64 amd64

已尝试切换Java 11和17,问题未解决;清理缓存前项目编译完全正常。


解决方案

1. 显式添加缺失的依赖包

报错提示的DownloadCommand类属于com.liferay.portal.tools.bundle.support包,当前Workspace插件的依赖中未自动引入该包,需手动添加到buildscript的依赖中:

buildscript {
    dependencies {
        classpath group: "biz.aQute.bnd", name: "biz.aQute.bnd", version: "5.2.0"
        classpath(group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "3.4.48") {
            exclude group: "biz.aQute.bnd", module: "biz.aQute.bnd"
        }
        // 添加缺失的bundle-support依赖,版本需与Workspace插件匹配
        classpath group: "com.liferay", name: "com.liferay.portal.tools.bundle.support", version: "3.0.12"
        classpath group: "net.saliman", name: "gradle-properties-plugin", version: "1.4.6"
    }
}

注:版本号建议匹配Workspace插件的依赖版本,可通过Maven仓库查询对应版本的Workspace插件依赖的bundle-support版本。

2. 强制刷新依赖

清理缓存后可能存在依赖下载不完整的情况,执行以下命令强制重新下载所有依赖:

./gradlew --refresh-dependencies build

3. 检查仓库配置

确保项目能访问Liferay官方仓库,在settings.gradle中添加或确认仓库配置:

pluginManagement {
    repositories {
        maven { url "https://repository-cdn.liferay.com/nexus/content/groups/public" }
        gradlePluginPortal()
        mavenCentral()
    }
}

4. 调整Workspace插件版本

若当前3.4.48版本存在依赖兼容问题,可尝试切换到稳定版本(如3.4.40),注意Gradle 6.6.1的兼容性:

classpath(group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "3.4.40") {
    exclude group: "biz.aQute.bnd", module: "biz.aQute.bnd"
}

5. 检查本地Gradle配置

确认~/.gradle/gradle.properties中无错误的镜像或代理配置,若有代理需确保配置正确,或临时关闭代理尝试下载依赖。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 12:21:00