gpt4 book ai didi

java - 将 Guava 添加到新的 Maven IntelliJ 模块

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:53:55 25 4
gpt4 key购买 nike

我在将 Google Guava 添加到我的 IntelliJ 项目时遇到问题。我尝试了以下方法:

  1. 来自 pom.xml ,使用 ALT-INSERT 并选择“依赖项”。我尝试搜索“google”、“guava”和“google-guava”。这些搜索都没有结果。

  2. guava website建议可以在“Maven Central”中找到 Guava 。我认为那是 http://repo1.maven.org/maven2/ .我尝试将该 URL 添加到 Project Settings->Maven->Repositories 的列表中。如果我将它添加到“Artifactory 或 Nexus 服务 URL”列表,当我单击“测试”时,我会收到消息“未找到存储库”。我找不到将 URL 添加到“索引 Maven 存储库”列表的方法(它只有一个“更新”按钮)。

  3. 我尝试添加这个 <dependency>片段直接到pom.xml

    <dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>10.0.1</version>
    </dependency>

    但是com.google.guava以红色突出显示,并带有提示找不到依赖项的工具提示。

如何让 IntelliJ 将 Guava 添加为我项目的 Maven 依赖项(无需自己下载)?

编辑

IntelliJ 已经配置的 Maven 存储库是:

我的“Indexed Maven Repositories”中的唯一条目是本地目录:

  • /home/benw/.m2/repository

最佳答案

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>10.0.1</version>
</dependency>

这对我来说是有效的,无需为我的所有 Maven 项目打开 auto-import 的 IntelliJ 进行任何特殊配置。如果没有自动导入,您必须告诉 IntelliJ 手动解决 pom.xml 更改。

确保您没有使用镜像或其他不正确的存储库声明覆盖 pom.xml~/.m2/settings.xml 中的默认值。

关于java - 将 Guava 添加到新的 Maven IntelliJ 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7970502/

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