在阴影jar中包含工件,但不会对使用该项目的人造成依赖

时间:2017-03-18 09:36:24

标签: java maven slf4j maven-shade-plugin

此问题与问题Maven Include Dependency in Shaded Jar Only非常相似。

我的问题是我想将slf4j-simple包含在阴影jar中,因为它是用于独立执行并需要正确记录。

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.21</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
    </dependency>

</dependencies>

我尝试使用<scope>provided</scope>,但未能将maven-shade-plugin包含在其中。

1 个答案:

答案 0 :(得分:0)

我发现的解决方案是在依赖声明中使用<optional>true</optional>。由于范围对我来说已经足够了,所以我没有意识到这个选项。

<dependencies>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.21</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
        <optional>true</optional>
    </dependency>

</dependencies>
相关问题