将 Guava 添加到新的 Maven IntelliJ 模块
我在将 Google Guava 添加到我的 IntelliJ 项目时遇到问题。我尝试了以下操作:
从
pom.xml
中,使用 ALT-INSERT 并选择“依赖项”。我尝试搜索“google”、“guava”和“google-guava”。这些搜索都没有结果。番石榴网站表明番石榴可以在“马文中心。”我认为这是
http://repo1.maven.org/maven2/
。我尝试将该 URL 添加到“项目设置”->“Maven”->“存储库”的列表中。如果我将其添加到“Artifactory 或 Nexus 服务 URL”列表中,当我单击“测试”时,我会收到消息“未找到存储库”。我找不到将 URL 添加到“索引 Maven 存储库”列表(只有一个“更新”按钮)的方法。我尝试将此
代码段直接添加到pom.xml
<依赖>;
com.google.guava ;番石榴 <版本>10.0.1但是
com.google.guava
以红色突出显示,并带有工具提示,指出无法找到依赖项。
如何让 IntelliJ 将 Guava 添加为我的项目的 Maven 依赖项(无需自己下载)?
编辑
IntelliJ 已配置的 Maven 存储库为:
- http://oss.sonatype.org/service/本地/
- http://repo.jfrog.org/artifactory/api/
- <一href="http://repository.jboss.org/nexus/service/local/" rel="noreferrer">http://repository.jboss.org/nexus/service/local/
中的唯一条目我的“Indexed Maven Repositories”是本地目录:
- /home/benw/.m2/repository
I'm having trouble adding Google Guava to my IntelliJ project. I've tried the following:
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.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).I tried adding this
<dependency>
snippet directly topom.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:
- http://oss.sonatype.org/service/local/
- http://repo.jfrog.org/artifactory/api/
- http://repository.jboss.org/nexus/service/local/
The only entry in my "Indexed Maven Repositories" is a local directory:
- /home/benw/.m2/repository
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是对我有用的方法,无需对 IntelliJ 进行任何特殊配置,并为我的所有 Maven 项目打开自动导入功能。如果没有自动导入,您必须告诉 IntelliJ 手动解决
pom.xml
更改。确保您没有使用镜像或其他不正确的存储库声明覆盖
pom.xml
或~/.m2/settings.xml
中的默认值。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 thepom.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.例如你的片段
成功地为我工作。
For exmaple your snippet
works for me successfully.
我相信如果本地存储库中还没有特定的工件,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.