【问题标题】:Using shaded jar as dependency causing shading in original project使用带阴影的 jar 作为依赖项导致原始项目中的阴影
【发布时间】:2017-12-16 09:12:37
【问题描述】:

我的项目依赖于另一个项目的阴影 jar。这个另一个项目正在使用shade插件将包a.b.c中的所有类重新定位为artifact A version 1shaded.a.b.c

我的项目也使用了这个artifact A but version 2。当我构建我的项目时,我看到我的项目中a.b.c.d 的导入语句(我希望来自artifact A version 2 并且不存在于artifact A version 1 中)已更改为shaded.a.b.c.d。我没有在我的原始项目中使用阴影,但是我看到依赖 jar 中的阴影插件导致我的原始项目中的阴影。

这是预期的行为吗?有没有办法阻止这种传递阴影?

其他项目的Shade插件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <shadedArtifactAttached>false</shadedArtifactAttached>
        <outputDirectory>${project.build.directory}</outputDirectory>
        <createDependencyReducedPom>true</createDependencyReducedPom>
        <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
        <shadeSourcesContent>true</shadeSourcesContent>
        <relocations>
            <relocation>
                <pattern>a.b.c</pattern>
                <shadedPattern>shaded.a.b.c</shadedPattern>
            </relocation>
        </relocations>
    </configuration>
</plugin>

【问题讨论】:

    标签: java maven maven-shade-plugin


    【解决方案1】:

    原来artifact A 也被定义为项目父 pom 中的依赖项(不是依赖项管理)。 “其他项目”首先由 maven 构建,它正在着色 artifact A,然后这个着色的工件(仍然不知道为什么)被该项目之后的所有其他子项目使用。

    将依赖项移至父项目中的依赖项管理并在子项目中定义各自的依赖项修复它。

    【讨论】:

      猜你喜欢
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-04
      • 2021-09-27
      • 1970-01-01
      • 2013-05-04
      相关资源
      最近更新 更多