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

如何解决Griffon子项目Gradle报错‘找不到gradlePluginPortal()方法’?

问题排查:Gradle子项目报错找不到gradlePluginPortal()方法

问题背景

为Griffon 1.0.1项目编写build.gradle时,单独构建可正常执行,但将其作为包含AsciiDoc文档子项目的大型项目子模块后,Gradle抛出如下错误:

Build file 'D:\Projects\Decoder2\rrDecoder\decoder\build.gradle' line: 6

A problem occurred evaluating project ':decoder'.
> Could not find method gradlePluginPortal() for arguments [] on repository container of type org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler.

即使进入子项目目录执行Gradle命令,仍会触发相同错误。父项目settings.gradle配置如下:

rootProject.name = 'rrDecoder'
include 'decoder'
include 'doc'

环境信息:Windows 11、Griffon 16.0.1、Java 1.8.0_372 (Azul)、Gradle 3.5.1、Groovy 2.4.10

排查方向及解决方案

  1. 核心原因定位:gradlePluginPortal()是Gradle 4.0及以上版本才引入的仓库配置方法,当前父项目使用的Gradle 3.5.1不支持该语法。子项目单独构建时可能使用了更高版本的Gradle(本地安装或自身wrapper配置),但作为子模块时会继承父项目的Gradle版本,因此触发报错。

  2. 检查父项目Gradle版本配置:
    查看父项目根目录下gradle/wrapper/gradle-wrapper.properties文件中的distributionUrl字段,确认是否指向Gradle 3.5.1。在子项目目录执行Gradle命令时,会优先使用父项目的wrapper配置,而非本地安装的Gradle版本。

  3. 修改子项目仓库配置:
    如果父项目必须保留Gradle 3.5.1,将子项目build.gradle中的gradlePluginPortal()替换为Gradle 3.5.1支持的等价仓库地址:

    repositories {
        // 替换gradlePluginPortal()
        maven { url 'https://plugins.gradle.org/m2/' }
        // 其他必要仓库,如mavenCentral()等
    }
    
  4. 统一Gradle版本(可选):
    如果允许升级父项目Gradle版本,可将父项目gradle-wrapper.properties中的distributionUrl修改为Gradle 4.0及以上的稳定版本(需选择兼容Griffon 1.0.1的版本),这样子项目的gradlePluginPortal()语法即可正常使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 12:22:10