【问题标题】:Include dependencies in Maven assembly without include the actual artifact在 Maven 程序集中包含依赖项而不包含实际的工件
【发布时间】:2012-06-27 15:30:40
【问题描述】:

我想创建一个 Maven 程序集,其中包含工件的传递依赖项,但实际上不包括工件本身。我试图从程序集中排除工件,但结果不包括它的依赖项。

ArtifactA 有 DependencyA、DependencyB

Assembly 应包含 DependencyA、DependencyB(不含 ArtifactA)

而且我更愿意这样做,而不必明确指定要包含在程序集中的依赖项,因为这将通过具有许多依赖项的多个项目来完成。

谢谢!

【问题讨论】:

  • 你能把程序集的目标改成在构建 jar 之前吗?
  • 这感觉有点绕圈子/反直觉。如果 ArtifactA 有一个版本可以消除对 A 的依赖怎么办?你的项目会中断吗?如果你依赖 A 和 B,为什么不直接把它们放在你的 POM 中呢?
  • 很抱歉没有提供更多上下文。我正在迁移我们的 Web 应用程序以使用 JBoss AS 7,它现在​​有一个模块概念,用于将 jar 文件和其他文件放在类路径上。我正在尝试创建一个 Maven 项目,该项目将构建 JBoss 模块以包含我们的 API jar 的依赖项,因此它的所有依赖项都不会包含在使用它的每个战争中。
  • 我试图避免比我已经不得不做的更彻底的改变,并且不能将 API jar 本身放在 JBoss 模块文件夹下,因为它被其他几个第三方应用程序使用不依赖于这些依赖项。只有战争文件需要这些依赖项,我将它们提供给 JBoss。是的,我意识到这是一场维护噩梦,但我在分散的团队中进行了更改,以便转向更合理的应用程序布局。
  • 这听起来像是“提供”范围的依赖项。这让我感到困惑为什么你使用 maven-assembly ?这个项目是 EAR 吗?

标签: java maven build


【解决方案1】:

我终于让它工作了。这将产生一个只包含depende的依赖项的工件

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>moduletest</groupId>
    <artifactId>moduletest</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <dependencies>
        <dependency>
            <groupId>dependency</groupId>
            <artifactId>dependency</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

程序集.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

    <id>module</id>

    <includeBaseDirectory>false</includeBaseDirectory>

    <formats>
        <format>zip</format>
    </formats>

    <dependencySets>
        <dependencySet>
            <excludes>
                <exclude>dependency:dependency</exclude>
            </excludes>
            <useProjectArtifact>false</useProjectArtifact>
            <useTransitiveDependencies>true</useTransitiveDependencies>
        </dependencySet>
    </dependencySets>

</assembly>

【讨论】:

  • 很好,但这将获得项目中所有工件的传递依赖关系,而不仅仅是dependency:dependency一个
猜你喜欢
  • 2023-03-30
  • 2011-12-12
  • 1970-01-01
  • 1970-01-01
  • 2015-03-29
  • 2014-04-04
  • 2016-02-23
  • 1970-01-01
相关资源
最近更新 更多