Hanchi Wang
Hanchi Wang

Reputation: 83

Missing transitive Maven dependency of local jar

Apologize for using acronyms in advance.

I'm working a Maven project Foo, which is depending on a local jar Bar. Bar is built with Maven as well and since it's a local jar, I created a local repo in Foo's folder structure, and put the jar there.

Bar.jar is put at base_dir_of_Foo\repo\group_ID\artifact_ID\1.0-SNAPSHOT\Bar.jar.

The problem I'm having is that when I'm running Foo, it's throwing a NoClassDefFoundError, because it can't find a class in one of Bar's dependencies. So, Foo is missing a transitive dependency through Bar.

One thing to notice is that when I'm running mvn clean package for Foo, I saw a warning says "Missing POM for Bar". Foo is calling B using reflection, and Foo is able to find classes defined in Bar, but looks like A can't figure out Bar's dependencies. Any idea why this is happening?

Local repos is defined in Foo's pom.xml:

<repositories>
    <repository>
        <id>local-repo</id>
        <name>Local</name>
       <url>file://${basedir}/repo</url>
   </repository>
</repositories>

Finally Foo is depending on Bar with default compile scope:

<dependency>
    <groupId>group_ID</groupId>
    <artifactId>artifact_ID</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

Update: I found of why pom of Bar is not found, it was because we I put Bar.jar at local repo, maven will only copy over the jar file into local repository cache, it will not extract pom.xml from the jar, is this expected?

Inside C:\Users\hancwang.m2\repository\group-id\Bar\1.0-SNAPSHOT, I'm seeing Bar-1.0-snapshot.jar being copied over, but there's no Bar-1.0-snapshot.pom.

Upvotes: 0

Views: 1873

Answers (1)

nandsito
nandsito

Reputation: 3852

Your <repository> definition is probably pointing to an incomplete repository, e.g. a repo missing a .pom file.

Assuming you build Bar source code locally, if you run mvn install in Bar you will install its artifact in the local repository. This way, Foo will find Bar normally. You don't need to define a <repository> in this case.

So, try to:

  • Run mvn install or mvn clean install in Bar
  • Remove the <repository> definition that points to a file:// jar

Upvotes: 1

Related Questions