从一个项目的程序集中排除共享依赖项

Excluding shared dependencies from the assembly of one project

在我对项目 B 的 maven-assembly-plugin 的 xml 配置中,项目的所有依赖项都导出到 lib/ 子文件夹。

<dependencySet>
    <useProjectArtifact>false</useProjectArtifact>
    <outputDirectory>lib</outputDirectory>
    <outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}
    </outputFileNameMapping>
    <scope>runtime</scope>
</dependencySet>

但是,项目 B 是项目 A 的插件,因此许多依赖项是共享的,并且已经存在于项目 A 的程序集中。

请问如何从 B 的程序集中排除所有这些共享依赖项?我看到有一个 <excludes> 标签,但即使它支持通配符,我也必须手动更新列表。我能以某种方式利用这两个项目的 pom 文件吗?

您可以使用范围解决此问题。在您的项目 B 中,必须按照提供的方式设置公共依赖项的范围。这使得您的依赖项(和子依赖项)仅在编译阶段使用。在您的 pom 中,依赖项应该如下所示:

       <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.2.2</version>
            <scope>provided</scope>
        </dependency>

希望对您有所帮助