Java Maven:无法解析依赖项(找不到工件)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28053423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven: Could not resolve dependencies (artifact not found)
提问by Wouter
I'm trying to build moquetteusing maven, being a complete newbie to Maven tough.
我正在尝试使用 maven构建moquette,作为 Maven 强悍的新手。
I'm using the following command to build.
我正在使用以下命令进行构建。
mvn clean install -U
mvn 干净安装 -U
And
和
mvn clean install -U | grep ERROR
mvn clean install -U | 错误
Results in the following:
结果如下:
[ERROR] Failed to execute goal on project moquette-broker: Could not resolve dependencies for project org.eclipse.moquette:moquette-broker:jar:0.7-SNAPSHOT: Could not find artifact org.mapdb:mapdb:jar:1.1.0-SNAPSHOT in Paho Releases (https://repo.eclipse.org/content/repositories/paho-releases/) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :moquette-broker
The full output of:
完整输出:
mvn clean install -e -X -U
mvn clean install -e -X -U
Can be found here.
可以在这里找到。
My pom.xmllooks like:
我的pom.xml看起来像:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<netty.version>4.0.24.Final</netty.version>
<source.version>1.7</source.version>
<target.version>1.7</target.version>
</properties>
<groupId>org.eclipse.moquette</groupId>
<artifactId>moquette-parent</artifactId>
<packaging>pom</packaging>
<version>0.7-SNAPSHOT</version>
<name>Moquette MQTT parent</name>
<url>http://code.google.com/p/moquette-mqtt/</url>
<modules>
<module>parser_commons</module>
<module>netty_parser</module>
<module>broker</module>
<module>distribution</module>
<module>bundle</module>
</modules>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</reporting>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${source.version}</source>
<target>${target.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
What is causing this problem and how do I fix this?
是什么导致了这个问题,我该如何解决这个问题?
采纳答案by Magnilex
According to the documentationof Moquette, a simple mvn clean install
should do it:
根据Moquette的文档,一个简单的mvn clean install
应该这样做:
After a git clone of the repository, cd into the cloned sources and: mvn clean package. In distribution/target directory will be produced the selfcontained tar for the broker with all dependencies and a running script.
在存储库的 git clone 之后,cd 进入克隆的源代码和:mvn clean package。在 distribution/target 目录中,将为具有所有依赖项和运行脚本的代理生成自包含的 tar。
In other words, you are doing everything right.
换句话说,您所做的一切都是正确的。
However, dependency org.mapdb:mapdb:jar:1.1.0-SNAPSHOTis missing (as of january 20th 2015). In other words, the installation instructions are insufficient.
但是,缺少依赖项org.mapdb:mapdb:jar:1.1.0-SNAPSHOT(截至 2015 年 1 月 20 日)。换句话说,安装说明是不够的。
By refering to the MapDB documentation, they publish nightly builds to a repository. If you add this as a repository, it will work (I just verified this myself):
通过参考MapDB 文档,他们将每晚构建发布到存储库。如果您将其添加为存储库,它将起作用(我自己刚刚验证了这一点):
<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
You can put this definition directly in your pom file, or configure it in the settings.xml file of the maven installation, as per instructions here.
你可以把这个定义直接放在你的 pom 文件中,或者按照这里的说明在Maven 安装的 settings.xml 文件中配置它。
So for your pom, it will look like this:
所以对于你的 pom,它看起来像这样:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<netty.version>4.0.24.Final</netty.version>
<source.version>1.7</source.version>
<target.version>1.7</target.version>
</properties>
<groupId>org.eclipse.moquette</groupId>
<artifactId>moquette-parent</artifactId>
<packaging>pom</packaging>
<version>0.7-SNAPSHOT</version>
<name>Moquette MQTT parent</name>
<url>http://code.google.com/p/moquette-mqtt/</url>
<modules>
<module>parser_commons</module>
<module>netty_parser</module>
<module>broker</module>
<module>distribution</module>
<module>bundle</module>
</modules>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</reporting>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${source.version}</source>
<target>${target.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
To explain this a bit more, maven checks for the needed artifacts in the repositories configured. In most cases, the artifacts exist in the "default" repositories, and no extra repositories are needed.
为了进一步解释这一点,maven 在配置的存储库中检查所需的工件。在大多数情况下,工件存在于“默认”存储库中,不需要额外的存储库。
On the other hand, let's say you have built your own maven artifact, and host your own maven repository. You publish the artifact to that repository. Now, if other users want to use it, they would have to do a configuration similar to the one above.
另一方面,假设您已经构建了自己的 Maven 工件,并托管了自己的 Maven 存储库。您将工件发布到该存储库。现在,如果其他用户想要使用它,他们必须做一个类似于上面的配置。
And by the way, -U
forces updates, which is not needed unless you really want to force maven to download/re-download the dependencies.
顺便说一下,-U
强制更新是不需要的,除非您真的想强制 maven 下载/重新下载依赖项。