简体   繁体   English

缺少本地jar的可传递Maven依赖项

[英]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 . 我正在一个Maven项目Foo ,它取决于本地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也是用Maven构建的,并且由于它是本地jar,因此我在Foo的文件夹结构中创建了本地存储库,然后将jar放在此处。

Bar.jar is put at base_dir_of_Foo\\repo\\group_ID\\artifact_ID\\1.0-SNAPSHOT\\Bar.jar . Bar.jar放在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. 我遇到的问题是,当我运行Foo ,它抛出了NoClassDefFoundError ,因为它无法在Bar的依赖项之一中找到一个类。 So, Foo is missing a transitive dependency through Bar . 因此, Foo通过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运行mvn clean package ,我看到一条警告,指出“ Bar缺少POM”。 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. Foo使用反射调用B ,而Foo能够找到在Bar定义的类,但是看起来A无法弄清Bar的依赖项。 Any idea why this is happening? 知道为什么会这样吗?

Local repos is defined in Foo 's pom.xml : 本地存储库在Foopom.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: 最后, Foo取决于具有默认编译范围的Bar

<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? 更新:我发现了为什么找不到Bar的pom的原因,这是因为我们将Bar.jar放在本地仓库中,maven只会将jar文件复制到本地存储库缓存中,而不会从jar中提取pom.xml,这是预期的吗?

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. 在C:\\ Users \\ hancwang.m2 \\ repository \\ group-id \\ Bar \\ 1.0-SNAPSHOT中,我看到Bar-1.0-snapshot.jar被复制了,但是没有Bar-1.0-snapshot.pom。

Your <repository> definition is probably pointing to an incomplete repository, eg a repo missing a .pom file. 您的<repository>定义可能指向一个不完整的存储库,例如,一个缺少.pom文件的存储库。

Assuming you build Bar source code locally, if you run mvn install in Bar you will install its artifact in the local repository. 假设您在本地构建Bar源代码,如果在Bar中运行mvn install ,则会将其工件安装在本地存储库中。 This way, Foo will find Bar normally. 这样,Foo将正常找到Bar。 You don't need to define a <repository> in this case. 在这种情况下,您不需要定义<repository>

So, try to: 因此,请尝试:

  • Run mvn install or mvn clean install in Bar 在Bar中运行mvn installmvn clean install
  • Remove the <repository> definition that points to a file:// jar 删除指向file:// jar的<repository>定义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM