Maven - 未解决部署在 Artifactory 上的工件的传递依赖项 [英] Maven - Transitive dependencies are not resolved for artifact deployed on Artifactory

查看:27
本文介绍了Maven - 未解决部署在 Artifactory 上的工件的传递依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目 - A 和 B,其中 A 依赖于 B.我将 B 打包为 jar 并将其部署在 maven 服务器(artifactory)上,然后将该 jar 作为对项目 A 的正常依赖项包含在 pom 文件中.B 的 jar 文件出现在项目 A 的 Maven 依赖项中,但项目 B 的依赖项没有显示在依赖层次结构中.它导致 B 的依赖项的类未找到异常.

I have two projects - A and B, where A is dependent on B. I package B as jar and deploy it on a maven server (artifactory), and then include that jar as a normal dependency on project A in pom file. jar file of B shows up in the Maven Dependencies of project A, but dependencies of project B are not shown in dependency hierarchy. It is causing class not found exception for dependencies of B.

但是,我的项目 A 和 B 位于同一个 Eclipse 工作区中.当我打开项目 B 时,项目 A 开始从工作区而不是远程存储库引用项目 B,一切正常.

However, my project A and B and in same eclipse workspace. When I open project B, project A starts referencing the project B from the workspace instead of remote repository and everything works well.

这个问题 - Maven.传递依赖最接近我的问题,但我的项目 B 的依赖不是可选的.

This question - Maven. Transitive dependencies was closest to my problem, but dependencies of my project B are NOT optional.

这里出了什么问题?

项目 B 的 POM

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myapp</groupId> 
  <artifactId>utils</artifactId>
  <version>1.0.0-RELEASE</version>
  <packaging>jar</packaging>

  <name>utils</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

<!-- Following doesn't get added to project A -->
  <dependencies>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>
  </dependencies>
</project>

项目 A 的 POM

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myapp</groupId>
  <artifactId>core-app</artifactId>
  <version>1.0.0-RELEASE</version>
  <packaging>jar</packaging>

  <name>core-app</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>com.myapp</groupId>
      <artifactId>utils</artifactId>
      <version>1.0.0-RELEASE</version>
    </dependency>
  </dependencies>
</project>

我正在使用 Maven 快速入门原型.我的项目的项目结构是(我打包成jar):

I am using maven quickstart archetype. Project structure of my projects is (which I package as jar):

project-name
  src/main/java
  src/test/java
  pom.xml

推荐答案

要成功解决传递依赖项,项目 B 的 jar 和 pom.xml 必须可以在 Maven 存储库中访问.将工件部署到远程存储库时,请确保 jar 和 pom.xml 均已部署并可供下载.

To successfully resolve transitive dependencies, project B's jar and pom.xml must be accessible in the Maven repository. When deploying artifacts to a remote repository, be sure both the jar and pom.xml are deployed and available for download.

将必备文件部署到远程仓库后,使用命令行构建项目A,指定构建Maven目标触发将所有依赖下载到本地Maven仓库中.mvn compilemvn package 之类的东西将触发下载并成功构建项目 A.

With the requisite files deployed to the remote repository, use the command line to build project A. Specify a build Maven target to trigger the downloading of all dependencies into the local Maven repository. Something like mvn compile or mvn package will trigger the downloads and successfully build project A.

一旦项目 B 的 jar 和 pom.xml 在本地 Maven 存储库中,在 Eclipse 中更新 Maven 项目,它们将正确重建和解析依赖项.

Once, project B's jar and pom.xml are in the local Maven repository, update the Maven projects in Eclipse and they will rebuild and resolve the dependencies correctly.

这篇关于Maven - 未解决部署在 Artifactory 上的工件的传递依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆