Использование плагина сборки maven для создания ZIP-файла, содержащего толстую банку (jar-with-dependencies)

Я использую плагин сборки maven и хочу создать ZIP-файл, который среди других файлов содержит толстую банку (jar-with-dependencies). Я не могу создать это за один раз, используя mvn package. Я могу либо раскомментировать конфигурацию для descriptor, либо раскомментировать jar-with-dependencies часть.

Раздел build pom.xml выглядит следующим образом:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptors>
                    <descriptor>src/main/assembly/dist.xml</descriptor>
                </descriptors>
                <finalName>sample-documentum-downloader</finalName>
            </configuration>

            <executions>
                <execution>
                    <id>jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <finalName>${project.artifactId}</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <mainClass>com.foo.DownloadDocuments</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>

                <execution>
                    <id>assemble-all</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

а dist.xml это:

<assembly>
<id>dist</id>
<formats>
    <format>zip</format>
</formats>
<files>
    <file>
        <source>target/${project.artifactId}.jar</source>
        <outputDirectory>/</outputDirectory>
    </file>
    <file>
        <source>data/input/docId.txt</source>
        <outputDirectory>data/input/</outputDirectory>
    </file>
    <file>
        <source>data/export/exported_files_will_be_created_here.txt</source>
        <outputDirectory>data/export/</outputDirectory>
    </file>
    <file>
        <source>src/main/resources/dfc.properties</source>
        <outputDirectory>/</outputDirectory>
    </file>
    <file>
        <source>src/main/resources/dfc.keystore</source>
        <outputDirectory>/</outputDirectory>
    </file>

</files>
<fileSets>
    <fileSet>
        <directory>${project.basedir}</directory>
        <includes>
            <include>*.cmd</include>
            <include>README.pdf</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
</fileSets>

How can I restructure to create a ZIP including the far JAR in one run.

Спасибо за поддержку.


person Marc Giombetti    schedule 18.01.2016    source источник


Ответы (2)


Проблема в том, что вы объявили элемент <configuration> глобальным для плагина. Это означает, что все исполнения унаследуют эту конфигурацию: assemble-all, но также и jar-with-dependencies. Таким образом, унаследованный <descriptors>, вероятно, связан с <descriptorRefs>.

Вам нужно переместить этот элемент <configuration> в конкретное исполнение assemble-all, как вы это делали для выполнения jar-with-dependencies.

person Tunaki    schedule 18.01.2016

Благодаря Тунаки, мой раздел build теперь выглядит так:

  <build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <finalName>${project.artifactId}</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <mainClass>com.foo.DownloadDocuments</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>

                <execution>
                    <id>assemble-all</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>src/main/assembly/dist.xml</descriptor>
                        </descriptors>
                        <finalName>sample-documentum-downloader</finalName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>
person Marc Giombetti    schedule 18.01.2016