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,提问作者Настя
相关产品推荐
相关产品推荐

