如何防止maven-assembly-plugin以疯狂的方式从dependencySet复制natives- *分类器

时间:2013-12-04 16:10:08

标签: java maven lwjgl maven-assembly-plugin

我有一个具有以下结构的项目:

.
├── bundleA
│   ├── pom.xml
│   └── src
├── bundleB
│   ├── pom.xml
│   └── src
├── distribution
│   ├── pom.xml
│   └── src
│       └── assemble
│           └── example.xml
└── pom.xml

bundleAbundleB poms是微不足道的,不会影响这个问题。

distribution pom.xml

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.example</groupId>
        <artifactId>testproject</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>distribution</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>distribution</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.lwjgl.lwjgl</groupId>
            <artifactId>lwjgl</artifactId>
            <version>2.9.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>distro-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/assemble/example.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

example.xml汇编描述符:

<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>example</id>
    <formats>
        <format>dir</format>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <includes>
                <include>org.lwjgl.lwjgl:lwjgl</include>
            </includes>
            <outputDirectory>/libs</outputDirectory>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>
    <moduleSets>
        <moduleSet>
            <useAllReactorProjects>true</useAllReactorProjects>
            <includes>
                <include>com.example:bundleA</include>
                <include>com.example:bundleB</include>
            </includes>
            <binaries>
                <outputDirectory>/bundles</outputDirectory>
                <unpack>false</unpack>
            </binaries>
        </moduleSet>
    </moduleSets>
</assembly>

问题在于:当我将lwjgl(或几乎任何其他项目与打包在已分类的子项目中的本机库)包含到distribution项目的依赖项中并在汇编描述符中引用它时 - 我在获得这种疯狂之后分配建立:

distribution/target/distribution-1.0-SNAPSHOT-example
├── bundles
│   ├── bundleA-1.0-SNAPSHOT-natives-linux.jar
│   ├── bundleA-1.0-SNAPSHOT-natives-osx.jar
│   ├── bundleA-1.0-SNAPSHOT-natives-windows.jar
│   ├── bundleA-1.0-SNAPSHOT.jar
│   ├── bundleB-1.0-SNAPSHOT-natives-linux.jar
│   ├── bundleB-1.0-SNAPSHOT-natives-osx.jar
│   ├── bundleB-1.0-SNAPSHOT-natives-windows.jar
│   └── bundleB-1.0-SNAPSHOT.jar
└── libs
    └── lwjgl-2.9.0.jar

换句话说,每个本地人 - * - 分类的lwjgl子项目都被神奇地复制了,具有唯一的名称(但是罐子的大小和内容完全相同)是我在项目中拥有的数量,这是疯狂的。

我想要的是指定lwjgl独立于平台的jar(不包含原生)的方法,或者从结果分发中排除这些natives- * jar的其他方法。

这是github上的这个项目:https://github.com/iamtakingiteasy/maven-assembly-plugin-insanity

1 个答案:

答案 0 :(得分:0)

嗯,这可能不是最佳或直接的解决方案,而是使用

<moduleSets>
    <moduleSet>
        ...
        <binaries>
            ...
            <includeDependencies>false</includeDependencies>
            ...
        </binaries>
        ...
    </moduleSet>
</moduleSets>

似乎有所帮助。关键是要开始查看捆绑选项,而不是试图对lwjgl本身做些什么。

此外,直接排除* -platform依赖项(再次,在bundle部分中)可能是解决方案:

<moduleSets>
    <moduleSet>
        ...
        <binaries>
            ...
            <excludes>
                <exclude>org.lwjgl.lwjgl:lwjgl-platform</exclude>
                <exclude>net.java.jinput:jinput-platform</exclude>
            </excludes>
            ...
        </binaries>
        ...
    </moduleSet>
</moduleSets>