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

n3h0vuf2  于 2023-08-03  发布在  Maven
关注(0)|答案(2)|浏览(120)

我创建了两个Maven项目。下面是两个项目的POM文件;
1.核心库-

<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.实用程序库-

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


现在核心库有一些外部依赖关系,例如。反射:反射等。因此,我的期望是,当我将核心库添加到实用程序库时,这些外部依赖关系应该自动添加到实用程序库的依赖关系树中。
但实际上,这些嵌套的依赖关系并没有被包含在实用程序库的依赖关系树中。
下面是我在实用程序库上运行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] ------------------------------------------------------------------------


我试过从this堆栈溢出问题的解决方案,但问题还没有解决。
有人能帮帮我吗?
P.S. -我必须实现这个嵌套的依赖包含而不创建一个胖/shaded/uber jar,因为它增加了实际的jar大小,我还想进一步使用utility-library作为一个maven依赖在其他项目。

**UPDATE:**当我尝试构建带有-X(enable debug logs)标志的utility-library时,我得到了以下错误:

[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 @

wqnecbli

wqnecbli1#

你的POM看起来很正确。
reflections是一个传递依赖,应该由Maven自动绘制。
如果你看不见它,请看mvn dependency:tree。它应该列在那里。
也许你的IDE在显示废话。

hwamh0ep

hwamh0ep2#

尝试不使用依赖管理

<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>
<dependencies>
    <dependency>
        <groupId>com.demo</groupId>
        <artifactId>core-library</artifactId>
    </dependency>
</dependencies>

字符串

相关问题