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

如何在Gradle版本目录中正确声明带分组的插件

问题原因

你的报错是因为混淆了插件ID和插件的Maven构件坐标:Gradle要求插件ID只能包含ASCII字母、数字、.、-、_,不允许出现冒号,你填写的com.google.gms:google-services是该插件的Maven坐标,不是合法的插件ID。

正确配置方法

1. 修改libs.versions.toml配置

将[plugins]块中的id字段替换为该插件的官方合法IDcom.google.gms.google-services即可:

[plugins]
google-services = { id = "com.google.gms.google-services", version = "4.3.10" }

如果配置后提示找不到插件,可在项目根目录的settings.gradle中补充插件仓库配置:

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

2. 保留原有build.gradle的插件引用写法

你原先的插件引用逻辑不需要修改,直接使用即可:

plugins {
    alias(libs.plugins.google.services)
}

补充说明

如果是适配旧项目需要沿用buildscript + apply plugin的写法,也可以按以下方式配置:

  1. libs.versions.toml中声明插件构件:
[versions]
google-services = "4.3.10"

[libraries]
google-services-plugin = { group = "com.google.gms", name = "google-services", version.ref = "google-services" }
  1. 根目录build.gradle中引入classpath:
buildscript {
    dependencies {
        classpath libs.google.services.plugin
    }
}
  1. 子模块中应用插件:
apply plugin: "com.google.gms.google-services"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 01:18:02