简体   繁体   English

使用 Maven 嵌套依赖项包含而不创建阴影 jar

[英]Nested dependency inclusion using maven without creating shaded jar

I have created two maven projects .我创建了两个 Maven 项目 Below are pom files of both projects;下面是两个项目的 pom 文件;

  1. core-library -核心库-
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.demo</groupId>
    <artifactId>core-library</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Core</name>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.reflections</groupId>
                <artifactId>reflections</artifactId>
                <version>0.9.12</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
        </dependency>
    </dependencies>
</project>
  1. utility-library -实用程序库-
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.demo</groupId>
    <artifactId>utility-library</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Utility</name>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.demo</groupId>
                <artifactId>core-library</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.demo</groupId>
            <artifactId>core-library</artifactId>
        </dependency>
    </dependencies>
</project> 

Now the core-library have some external dependencies eg org.reflections:reflections etc. So my expectation is when I add core-library to the utility-library, these external dependencies should automatically get added to dependency tree of utility-library.现在核心库有一些外部依赖项,例如 org.reflections:reflections 等。所以我的期望是当我将核心库添加到实用程序库时,这些外部依赖项应该自动添加到实用程序库的依赖树中。

But in actual, these nested dependencies are not getting included in dependency tree of utility-library.但实际上,这些嵌套的依赖并没有包含在实用程序库的依赖树中。

Below is the output when I run mvn dependency:tree on utility-library以下是我在实用程序库上运行mvn dependency:tree时的输出

 --- maven-dependency-plugin:2.8:tree (default-cli) @ utility-library ---
[INFO] com.demo:utility-library:jar:0.0.1-SNAPSHOT
[INFO] +- com.demo:core-library:jar:0.0.1-SNAPSHOT:compile
INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

I tried solution from this stack overflow question, but the problem is not solved yet.我尝试了这个堆栈溢出问题的解决方案,但问题还没有解决。

Can someone please help me with this?有人可以帮我解决这个问题吗?

PS - I have to achieve this nested dependency inclusion without creating a fat/shaded/uber jar as it increses the actual jar size and I also want to further use utility-library as a maven dependency in other project. PS - 我必须在不创建 fat/shaded/uber jar 的情况下实现这种嵌套的依赖包含,因为它增加了实际的 jar 大小,我还想进一步使用实用程序库作为其他项目中的 maven 依赖。

UPDATE: When I tried building utility-library with -X (enable debug logs) flag, I got following errors,更新:当我尝试使用 -X(启用调试日志)标志构建实用程序库时,出现以下错误,

[WARNING] The POM for com.demo:core-library:jar:0.0.1-SNAPSHOT is invalid, transitive dependencies (if any) will not be available: 3 problems were encountered while building the effective model for com.demo:core-library:0.0.1-SNAPSHOT
[ERROR] Invalid packaging for parent POM com.demo:core-library:0.0.1-SNAPSHOT, must be "pom" but is "jar" @
[ERROR] Invalid packaging for parent POMcom.demo:core-library:0.0.1-SNAPSHOT, must be "pom" but is "jar" @
[FATAL] The parents form a cycle: com.demo:core-library:0.0.1-SNAPSHOT -> com.demo:core-library:0.0.1-SNAPSHOT @ 

Your POMs look correct.你的 POM 看起来是正确的。

reflections is a transitive dependency that should be drawn automatically by Maven. reflections是一个传递依赖,应该由 Maven 自动绘制。

If you cannot see it, have a look at mvn dependency:tree .如果您看不到它,请查看mvn dependency:tree It should be listed there.它应该列在那里。

Maybe your IDE is showing nonsense.也许你的 IDE 是在胡说八道。

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

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