将 Guava 添加到新的 Maven IntelliJ 模块

发布于 2024-12-12 20:31:02 字数 1451 浏览 0 评论 0原文

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

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

  2. 番石榴网站表明番石榴可以在“马文中心。”我认为这是http://repo1.maven.org/maven2/。我尝试将该 URL 添加到“项目设置”->“Maven”->“存储库”的列表中。如果我将其添加到“Artifactory 或 Nexus 服务 URL”列表中,当我单击“测试”时,我会收到消息“未找到存储库”。我找不到将 URL 添加到“索引 Maven 存储库”列表(只有一个“更新”按钮)的方法。

  3. 我尝试将此 代码段直接添加到 pom.xml

    <依赖>;
        com.google.guava;
        番石榴
        <版本>10.0.1
    
    

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

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

编辑

IntelliJ 已配置的 Maven 存储库为:

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

  • /home/benw/.m2/repository

I'm having trouble adding Google Guava to my IntelliJ project. I've tried the following:

  1. From pom.xml, using ALT-INSERT and selecting "Dependency". I tried searching for "google", "guava", and "google-guava". There were no results for any of these searches.

  2. The guava website suggests that guava can be found in "Maven Central." I think that is http://repo1.maven.org/maven2/. I tried adding that URL to the list at Project Settings->Maven->Repositories. If I add it to the "Artifactory or Nexus Service URLs" list, when I click "Test" I get the message "No repositories found." I cannot find a way to add the URL to the list of "Indexed Maven Repositories" (which only has an "Update" button).

  3. I tried adding this <dependency> snippet directly to pom.xml

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

    but com.google.guava gets highlighted in red with a tooltip saying that dependency cannot be found.

How can I get IntelliJ to add Guava as a maven dependency for my project (without downloading it myself)?

Edit

The Maven Repositories that IntelliJ is already configured with are:

The only entry in my "Indexed Maven Repositories" is a local directory:

  • /home/benw/.m2/repository

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不羁少年 2024-12-19 20:31:02
<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>10.0.1</version>
</dependency>

这就是对我有用的方法,无需对 IntelliJ 进行任何特殊配置,并为我的所有 Maven 项目打开自动导入功能。如果没有自动导入,您必须告诉 IntelliJ 手动解决 pom.xml 更改。

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

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

this is what is working for me without any special configuration for IntelliJ with auto-import turned on for all my Maven projects. Without auto-import you have to tell IntelliJ to manually resolve the pom.xml changes.

Make sure you are not overriding the defaults in the pom.xml or the ~/.m2/settings.xml with a mirrors or other incorrect repository declarations.

∞梦里开花 2024-12-19 20:31:02
  1. ALT-INSERT 适用于本地存储库中已有的依赖项。
  2. http://repo1.maven.org/maven2 无法浏览,但工件的正确链接有效。 尝试 guava 10.0.1
  3. 例如,在添加依赖项片段后 您应该重新导入 Maven 项目。
    例如你的片段
<依赖>;
    com.google.guava;
    番石榴
    <版本>10.0.1

成功地为我工作。

  1. ALT-INSERT works with dependecies you already have in local repository.
  2. http://repo1.maven.org/maven2 can not be browsed, but correct link to artifacts works. E.g. try guava 10.0.1
  3. After adding dependency snippet you should reimport Maven project.
    For exmaple your snippet
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>10.0.1</version>
</dependency>

works for me successfully.

心房敞 2024-12-19 20:31:02

我相信如果本地存储库中还没有特定的工件,Maven 本身(默认情况下)会自动从 Maven Central 中提取。因此,您需要做的就是确保 IDEA 指向“/home/benw/.m2/repository”作为您的本地存储库,并且“/home/benw/.m2/settings.xml”中没有任何更改“这将阻止 Maven 访问 Central。

I believe Maven itself (by default) pulls from Maven Central automatically if it does not already have a particular artifact in the local repository. So all you should need to do is ensure that IDEA is pointing to "/home/benw/.m2/repository" as your local repository and that there aren't any changes in "/home/benw/.m2/settings.xml" that would be preventing Maven from accessing Central.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文