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

时间:2013-09-11 03:27:14

标签: java maven build compilation pom.xml

背景

尝试使用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>

问题

运行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注意到可能存在的一些问题,但这些问题似乎都不适用。

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

  1. 将默认设置复制到Maven的用户主目录:
    cp /opt/apache-maven-3.1.0/conf/settings.xml $HOME/.m2/.
  2. 编辑用户的settings.xml文件。
  3. 更新本地存储库的值:
    ${user.home}/.m2/repository
  4. 保存文件。
  5. 我也尝试了以下命令:

    mvn -U
    mvn clear -U
    

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

    问题

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

    相关

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

2 个答案:

答案 0 :(得分: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>

groupId的{​​{1}}不正确。正确的值为net.sourceforge

答案 1 :(得分: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中添加类似以下内容的代码:
  5. 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>
    
相关问题