在Maven程序集中包含依赖项,而不包括实际的工件

时间:2012-06-27 15:30:40

标签: java maven build

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

ArtifactA具有DependencyA,DependencyB

程序集应包含DependencyA,DependencyB(不带ArtifactA)

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

谢谢!

1 个答案:

答案 0 :(得分:1)

我终于开始工作了。这将生成仅包含依赖

的依赖项的工件

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

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