缺少项目的POM,没有可用的依赖项信息

问题描述 投票:42回答:2

Background

尝试使用Java 1.7的干净安装Apache Maven 3.1.0将Java库添加到本地Maven存储库。以下是添加Java归档文件的方法:

mvn install:install-file \
  -DgroupId=net.sourceforge.ant4x \
  -DartifactId=ant4x \
  -Dversion=0.3.0 \
  -Dfile=ant4x-0.3.0.jar \
  -Dpackaging=jar

这创建了以下目录结构:

$HOME/.m2/repository/net/sourceforge/ant4x/
├── 0.3.0
│   ├── ant4x-0.3.0.jar.lastUpdated
│   └── ant4x-0.3.0.pom.lastUpdated
└── ant4x
    ├── 0.3.0
    │   ├── ant4x-0.3.0.jar
    │   ├── ant4x-0.3.0.pom
    │   └── _remote.repositories
    └── maven-metadata-local.xml

项目的pom.xml文件引用了依赖项目(上面的树),如下所示:

<properties>
  <java-version>1.5</java-version>
  <net.sourceforge.ant4x-version>0.3.0</net.sourceforge.ant4x-version>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
<dependency>
  <groupId>net.sourceforge</groupId>
  <artifactId>ant4x</artifactId>
  <version>${net.sourceforge.ant4x-version}</version>
  <scope>provided</scope>
</dependency>

Problem

运行mvn compile后,返回以下错误(full log on Pastebin):

[ERROR] Failed to execute goal on project ant4docbook: Could not resolve dependencies for project net.sourceforge:ant4docbook:jar:0.6-SNAPSHOT: Failure to find net.sourceforge:ant4x:jar:0.3.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

documentation指出了一些可能存在的问题,但这些问题似乎都不适用。

Ideas

我根据文档尝试了以下内容:

  1. 将默认设置复制到Maven的用户主目录: cp /opt/apache-maven-3.1.0/conf/settings.xml $ HOME / .m2 /。
  2. 编辑用户的settings.xml文件。
  3. 更新本地存储库的值: $ {}的user.home /。平方米/库
  4. 保存文件。

我也尝试了以下命令:

mvn -U
mvn clear -U

我尝试使用Maven 3.0.5,但也失败了。

Question

你如何强迫Maven使用本地版本的库,而不是试图寻找一个尚未下载的库?

Related

相关问题和未解决问题的信息:

java maven build compilation pom.xml
2个回答
16
投票

更改:

<!-- ANT4X -->
<dependency>
  <groupId>net.sourceforge</groupId>
  <artifactId>ant4x</artifactId>
  <version>${net.sourceforge.ant4x-version}</version>
  <scope>provided</scope>
</dependency>

至:

<!-- ANT4X -->
<dependency>
  <groupId>net.sourceforge.ant4x</groupId>
  <artifactId>ant4x</artifactId>
  <version>${net.sourceforge.ant4x-version}</version>
  <scope>provided</scope>
</dependency>

groupIdnet.sourceforge不正确。正确的值是net.sourceforge.ant4x


3
投票

范围<scope>provided</scope>让您有机会告诉jar在运行时可用,所以不要捆绑它。这并不意味着你在编译时不需要它,因此maven会尝试下载它。

现在我想,下面的maven工件根本不存在。我尝试搜索谷歌,但无法找到。因此,您遇到了这个问题。

groupId更改为<groupId>net.sourceforge.ant4x</groupId>以获取最新的jar。

<dependency>
  <groupId>net.sourceforge.ant4x</groupId>
  <artifactId>ant4x</artifactId>
  <version>${net.sourceforge.ant4x-version}</version>
  <scope>provided</scope>
</dependency>

编辑:

这个问题的解决方案之一是解决方案

  1. 运行你自己的maven回购。
  2. 下载jar
  3. 将jar安装到存储库中。
  4. 在你的pom.xml中添加一个代码:

.

where http://localhost/repo is your local repo URL
<repositories>
    <repository>
        <id>wmc-central</id>
        <url>http://localhost/repo</url>
    </repository>
..................... Other repository config ......................
</repositories>
© www.soinside.com 2019 - 2024. All rights reserved.