英文:
Intellij Maven [Cannot resolve dependency]
问题
我在我的服务器上(api.lielamar.com)上设置了Nexus,并上传了我第一个名为PacketManager的项目。
你可以在这里查看它: https://api.lielamar.com/#browse/browse:maven-public
出于某种原因,当我尝试通过pom.xml导入它时,它就是无法工作。我对Maven相当新,对Nexus几乎是全新的,所以可能是一个新手问题。
我尝试使用谷歌,但找不到直接适用于我的直接答案。
这是我的代码:
<repositories>
<repository>
<id>lielamar-repo</id>
<url>https://api.lielamar.com/service/rest/repository/browse/maven-public/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.lielamar.packetmanager</groupId>
<artifactId>PacketManager</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
我还在使用Spigot仓库,它运作得很好。
这是我在IDE中看到的情况
感谢您的时间!
编辑:
其中一个问题是,当我运行mvn install或尝试通过IntelliJ编译时,我的依赖关系调用了不同的仓库。
在将以下代码添加到settings.xml后,我开始收到不同的错误:
<mirrors>
<mirror>
<id>lielamar-mirror</id>
<name>lielamar镜像</name>
<url>https://api.lielamar.com/service/rest/repository/browse/maven-public/</url>
<mirrorOf>lielamar-api</mirrorOf>
</mirror>
</mirrors>
在添加了上述代码后,我得到的错误是:
[ERROR] Failed to execute goal on project TestPlugin:
Could not resolve dependencies for project com.lielamar.testplugin:TestPlugin:jar:1.0:
Failure to find com.lielamar.packetmanager:PacketManager:jar:1.0 in
https://api.lielamar.com/service/rest/repository/browse/maven-public/ was cached in the local repository,
resolution will not be reattempted until the update interval of lielamar-mirror has elapsed or updates are forced -> [Help 1]
我从命令提示符中运行了mvn dependency:purge-local-repository
命令,它成功构建了,但是IntelliJ仍然给我一个错误:https://prnt.sc/unxppz
英文:
I set up Nexus on my server (api.lielamar.com) and uploaded my first project called PacketManager.
You can view it here: https://api.lielamar.com/#browse/browse:maven-public
For some reason, when I try to import it through pom.xml it just doesn't work. I am fairly new to Maven and extremely new to Nexus so it might be a newbie question.
I tried using google and couldn't find a direct answer that worked for me.
There's my code:
<repositories>
<repository>
<id>lielamar-repo</id>
<url>https://api.lielamar.com/service/rest/repository/browse/maven-public/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.lielamar.packetmanager</groupId>
<artifactId>PacketManager</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
I am also using the spigot repository which is working just fine.
This is what I see on the IDE
Thank you for your time!
Edit:
One of the problems were that I had my dependency calling a different repo when running mvn install or trying to compile through intellij.
After adding the following code to setting.xml, I started getting a different error:
<mirrors>
<mirror>
<id>lielamar-mirror</id>
<name>lielamar mirror</name>
<url>https://api.lielamar.com/service/rest/repository/browse/maven-public/</url>
<mirrorOf>lielamar-api</mirrorOf>
</mirror>
</mirrors>
The error I was getting after adding the above code was:
[ERROR] Failed to execute goal on project TestPlugin:
Could not resolve dependencies for project com.lielamar.testplugin:TestPlugin:jar:1.0:
Failure to find com.lielamar.packetmanager:PacketManager:jar:1.0 in
https://api.lielamar.com/service/rest/repository/browse/maven-public/ was cached in the local repository,
resolution will not be reattempted until the update interval of lielamar-mirror has elapsed or updates are forced -> [Help 1]`
I run the command mvn dependency:purge-local-repository
from the cmd and it was built successfully, however, intellij still gives me an error: https://prnt.sc/unxppz
答案1
得分: 2
你在 Nexus 中的 JAR 文件以 ..jar
结尾,所以在上传时可能犯了错误(使用了两个点而不是一个)。
英文:
Your JAR files in the Nexus end with ..jar
, so you probably made a mistake when uploading them (two dots instead of one).
答案2
得分: 0
你需要在你的 pom.xml 文件中添加以下内容:
<distributionManagement>
<snapshotRepository>
<repository>
<id>you-repository-name</id>
<url>http://you-repository-url</url>
</repository>
</snapshotRepository>
</distributionManagement>
英文:
You need to add in your pom.xml
<distributionManagement>
<snapshotRepository>
<repository>
<id>you-repository-name</id>
<url>http://you-repository-url</url>
</repository>
<snapshotRepository>
</distributionManagement>
答案3
得分: 0
这对我来说看起来还不错。你是否查看了文档?也许你需要首先设置 Maven。为了确保这是一个 Maven 的问题,还可以尝试从 Intellij 外部运行 Maven 构建 - 这只是一个常见的做法,因为我怀疑 Intellij 与此无关。
英文:
It looks ok to me. Have you checked the docs? Perhaps you need to set up Maven first. To make sure it is a Maven issue, also try running your Maven build from outside of Intellij -- just a common practice, as I doubt it is the case that Intellij has anything to do with it.
答案4
得分: 0
用 https://api.lielamar.com/repository/maven-releases/
替换您的存储库网址。
您现在的存储库网址指向一个组,在 Nexus 上检查一下。
如果可能的话,可能需要以不同的方式引用组。
或者您可能需要类似这样的内容 https://docs.gitlab.com/ee/user/packages/maven_repository/#group-level-maven-endpoint
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/groups/GROUP_ID/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/PROJECT_ID/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/PROJECT_ID/packages/maven</url>
</snapshotRepository>
</distributionManagement>
英文:
Replace your repository url by https://api.lielamar.com/repository/maven-releases/
The one you have points to a group, if you check on nexus.
The group one might need to be referenced in a different way if they can be referenced at all.
or you might need something like this https://docs.gitlab.com/ee/user/packages/maven_repository/#group-level-maven-endpoint
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/groups/GROUP_ID/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/PROJECT_ID/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/PROJECT_ID/packages/maven</url>
</snapshotRepository>
</distributionManagement>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论