gpt4 book ai didi

java - Gradle 找不到 guava-*version*-cdi1.0.jar

转载 作者:行者123 更新时间:2023-12-04 08:11:56 26 4
gpt4 key购买 nike

可能是显而易见的事情,但这个问题让我卡住了一段时间。

一些库需要 com.google.guava:guava:21.0 作为依赖项,但是 gradle 无法从 maven 存储库中获取它。这是一个遗留项目,所以版本不是最新的。

错误日志:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find guava-21.0-cdi1.0.jar (com.google.guava:guava:21.0).
Searched in the following locations:
https://repo.maven.apache.org/maven2/com/google/guava/guava/21.0/guava-21.0-cdi1.0.jar

guava-21.0.jar(无 -cdi1.0 后缀)存在于该路径上。为什么 gradle 向文件名添加 -cdi1.0 后缀,是否可以禁用此功能?或者我只是误解了一些东西,还有其他东西在起作用?

我试图单独指定 guava dep compile(group: 'com.google.guava', name: 'guava', version: '21.0'),但是它不会影响任何东西。

build.gradle:(由 gradle init 从 maven pom.xml 生成)

plugins {
id 'java'
id 'maven-publish'
}

repositories {
mavenCentral()
maven {
url = 'http://repo.maven.apache.org/maven2'
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web:1.4.1.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-jdbc:1.4.1.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-actuator:1.4.1.RELEASE'
... etc other deps
}

group = 'com.springapp'
version = '1.0-SNAPSHOT'
description = 'someproj'
java.sourceCompatibility = JavaVersion.VERSION_1_8

publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

来自 gradle --debug 构建:

2021-01-31T10:59:27.736-0300 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver] Attempting to resolve component for com.google.guava:guava:30.1-jre using repositories [MavenRepo, maven]
2021-01-31T10:59:27.736-0300 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Using cached module metadata for module 'com.google.guava:guava:30.1-jre' in 'MavenRepo'
2021-01-31T10:59:27.737-0300 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver] Using com.google.guava:guava:30.1-jre from Maven repository 'MavenRepo'
2021-01-31T10:59:27.737-0300 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate com.google.guava:guava:30.1-jre configuration compile doesn't have attribute org.gradle.dependency.bundling
2021-01-31T10:59:27.737-0300 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate com.google.guava:guava:30.1-jre configuration compile doesn't have attribute org.gradle.jvm.version
2021-01-31T10:59:27.737-0300 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate com.google.guava:guava:30.1-jre configuration runtime doesn't have attribute org.gradle.dependency.bundling
2021-01-31T10:59:27.737-0300 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate com.google.guava:guava:30.1-jre configuration runtime doesn't have attribute org.gradle.jvm.version
2021-01-31T10:59:27.738-0300 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate com.google.guava:guava:30.1-jre configuration platform-compile attribute org.gradle.category value {org.gradle.category=platform, org.gradle.status=release, org.gradle.usage=java-api} doesn't requested value library
2021-01-31T10:59:27.738-0300 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate com.google.guava:guava:30.1-jre configuration platform-runtime attribute org.gradle.category value {org.gradle.category=platform, org.gradle.status=release, org.gradle.usage=java-runtime} doesn't requested value library
2021-01-31T10:59:27.738-0300 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate com.google.guava:guava:30.1-jre configuration enforced-platform-compile attribute org.gradle.category value {org.gradle.category=enforced-platform, org.gradle.status=release, org.gradle.usage=java-api} doesn't requested value library
2021-01-31T10:59:27.738-0300 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate com.google.guava:guava:30.1-jre configuration enforced-platform-runtime attribute org.gradle.category value {org.gradle.category=enforced-platform, org.gradle.status=release, org.gradle.usage=java-runtime} doesn't requested value library
2021-01-31T10:59:27.738-0300 [DEBUG] [org.gradle.internal.component.model.ComponentAttributeMatcher] Selected matches [com.google.guava:guava:30.1-jre configuration compile] from candidates [com.google.guava:guava:30.1-jre configuration compile, com.google.guava:guava:30.1-jre configuration runtime, com.google.guava:guava:30.1-jre configuration platform-compile, com.google.guava:guava:30.1-jre configuration platform-runtime, com.google.guava:guava:30.1-jre configuration enforced-platform-compile, com.google.guava:guava:30.1-jre configuration enforced-platform-runtime] for {org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.version=8, org.gradle.libraryelements=classes, org.gradle.usage=java-api}

然后是:

2021-01-31T10:59:27.938-0300 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Found artifact 'guava-30.1-jre.jar (com.google.guava:guava:30.1-jre)' in resolver cache: /Users/hopa/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/30.1-jre/d0c3ce2311c9e36e73228da25a6e99b2ab826f/guava-30.1-jre.jar
2021-01-31T10:59:27.940-0300 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Detected non-existence of artifact 'guava-30.1-jre-cdi1.0.jar (com.google.guava:guava:30.1-jre)' in resolver cache

这是唯一一次在调试日志中提到 cdi 分类器 Detected non-existence of artifact 'guava-30.1-jre-cdi1.0.jar (com.google.guava:guava:30.1-jre) ' 在解析器缓存中,构建失败消息除外

最佳答案

cdi-1.0后缀是一个分类器,通常在 pom 中看到像:<classifier>cdi1.0</classifier> .据我所知,它真的只存在于 Guava 15 中,所以我会到处检查以找出违规者。一些尝试:

  • 检查传递依赖。使用 gradle dependencies寻找试图拉入的东西 com.google.guava:guava:21.0和不正确的分类器。也许其中之一做错了,您可以尝试更改版本或强制执行不同的操作。希望强制不会导致too much trouble with the classifier .如果时间允许,您可以尝试查找可能不匹配的依赖项。
  • 在您的 IDE 中重新启动/使缓存失效,以及清除 Gradle 缓存。

关于java - Gradle 找不到 guava-*version*-cdi1.0.jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65909484/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com