Maven - Transitive dependencies are not resolved for artifact deployed on Artifactory

让人想犯罪 __ 提交于 2019-12-01 18:21:22

问题


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.

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.

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

Whats going wrong here?

POM for project B

<?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>

POM for project A

<?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>

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

回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/43999612/maven-transitive-dependencies-are-not-resolved-for-artifact-deployed-on-artifa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!