【问题标题】:Why maven causes dependencies errors?为什么maven会导致依赖错误?
【发布时间】:2012-11-13 08:54:52
【问题描述】:
为什么 .pom 文件中的一些 maven 依赖项会导致如下错误:Missing artifact nonfree-lingpipe:lingpipe:jar:2.3.1?所有依赖项都列在 .pom 文件中。在 .m2 文件夹中,我有所有依赖文件夹,但不是所有 jar:所以对于 nonfree-lingpipe:lingpipe:jar:2.3.1 - 没有 jar,但我有一个用于 4.1.0。为什么maven没有那个,而是搜索2.3.1?我在.pom 文件中没有看到任何版本,只有名称。
【问题讨论】:
标签:
eclipse
maven
dependencies
m2eclipse
pom.xml
【解决方案1】:
Maven 依赖项必须指定版本号。如果您看不到列出的一个,那么您的 POM 或其父项之一中必须有一个 dependency management 元素:
<project>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>nonfree-lingpipe</groupId>
<artifactId>lingpipe:jar</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
</dependencyManagement>
...
</project>
要更改到 4.1.0,您必须在依赖项声明中明确指定版本,或者查找依赖项管理部分并在那里进行更改。
【解决方案2】:
dependencyManagement 中的定义仅定义了应该在哪个版本中使用它的工件,但并未真正使用此工件。此外给定的示例:
<dependencies>
<dependency>
<groupId>nonfree-lingpipe</groupId>
<artifactId>lingpipe:jar</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
错误,因为 artifactId 不应该包含冒号。正确的方法是:
<dependencies>
<dependency>
<groupId>nonfree-lingpipe</groupId>
<artifactId>lingpipe</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
此外,您需要在dependencyManagement 块之外定义此依赖项才能真正使用此依赖项。