Maven-对于在Artifactory上部署的工件,无法解决传递依赖性 [英] Maven - Transitive dependencies are not resolved for artifact deployed on Artifactory

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

问题描述

我有两个项目-A和B,其中A依赖于B.我将B打包为jar并将其部署在maven服务器上(人工工厂),然后将该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

推荐答案

要成功解决传递依赖关系,必须在Maven存储库中访问项目B的jar和pom.xml.将工件部署到远程存储库时,请确保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天全站免登陆