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

Gradle添加AsyncAPI插件报错:为何查找错误的Maven仓库路径?

问题:AsyncAPI Gradle插件依赖解析失败疑惑

我按照Gradle插件官网提供的方式,在build.gradle中添加com.asyncapi.asyncapi-gradle-plugin插件,配置如下:

buildscript {
  repositories {
    maven {
      url = uri("https://plugins.gradle.org/m2/")
    }
  }
  dependencies {
    classpath("com.asyncapi:asyncapi-gradle-plugin:1.0.0-EAP.1")
  }
}

apply(plugin = "com.asyncapi.asyncapi-gradle-plugin")

运行时出现如下错误:

A problem occurred configuring root project 'java-backend'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find com.asyncapi:asyncapi-core:1.0.0-SNAPSHOT.
     Searched in the following locations:
       - https://plugins.gradle.org/m2/com/asyncapi/asyncapi-core/1.0.0-SNAPSHOT/maven-metadata.xml
       - https://plugins.gradle.org/m2/com/asyncapi/asyncapi-core/1.0.0-SNAPSHOT/asyncapi-core-1.0.0-SNAPSHOT.pom
     Required by:
         project : > com.asyncapi:asyncapi-gradle-plugin:1.0.0-EAP.1 > com.asyncapi:asyncapi-plugin-core:1.0.0-EAP

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

我认为仓库应查找路径https://plugins.gradle.org/m2/com/asyncapi/asyncapi-gradle-plugin/1.0.0-EAP.1/,为何Gradle会去查找其他路径?


解答

  • Gradle解析依赖时,不会只下载你直接声明的插件本身,还会自动递归解析该插件整条依赖链上的所有依赖库。从错误信息可以看到:你指定的asyncapi-gradle-plugin:1.0.0-EAP.1依赖了asyncapi-plugin-core:1.0.0-EAP,而这个核心库又依赖了asyncapi-core:1.0.0-SNAPSHOT。
  • 你配置的https://plugins.gradle.org/m2/仓库中没有asyncapi-core:1.0.0-SNAPSHOT这个快照版本的组件,所以Gradle会抛出找不到依赖的错误。
  • 你提到的路径是插件自身的存储位置,但Gradle需要获取插件依赖链上的所有组件,因此才会去查找asyncapi-core相关的路径。

解决办法

在buildscript的仓库配置中添加能提供该快照版本的仓库,示例配置如下:

buildscript {
  repositories {
    maven {
      url = uri("https://plugins.gradle.org/m2/")
    }
    // 添加快照仓库,用于获取asyncapi-core的快照版本
    maven {
      url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
    }
  }
  dependencies {
    classpath("com.asyncapi:asyncapi-gradle-plugin:1.0.0-EAP.1")
  }
}

apply(plugin = "com.asyncapi.asyncapi-gradle-plugin")

内容的提问来源于stack exchange,提问作者Настя

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 10:55:37