【问题标题】:Maven assembly plugin not building files from descriptorMaven 程序集插件不从描述符构建文件
【发布时间】:2019-04-11 00:36:20
【问题描述】:

我正在尝试创建一个名为my-project-2.0.tar.gztar.gz,在该文件中有一个zip 文件,其中包含我所有的Java 类,名为my-project.zip。原因是某些脚本文件会寻找这种格式。

我已经在我的pom 文件和描述符文件中设置了maven 程序集插件。

这个问题是当我运行我的构建时,插件和描述符被忽略了。

eclipse 中的目标是clean package

<pluginManagement>
<plugins>
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.5.5</version>
    <executions>
        <execution>
            <phase>package</phase>
            <id>assemble</id>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/prep.xml</descriptor>
                </descriptors>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
        </execution>
        <execution>
            <phase>package</phase>
            <id>bundle</id>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <finalName>my-project-2.0</finalName>
                <descriptors>
                    <descriptor>src/assembly/bundle.xml</descriptor>
                </descriptors>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
        </execution>
    </executions>
</plugin>
</plugins>
</pluginManagement>

这是包描述符:

<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>bundle-id</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>target</directory>
            <includes>
                <include>my-project.zip</include>
            </includes>
            <outputDirectory></outputDirectory>
        </fileSet>
        <fileSet>
            <directory>src/assembly</directory>
            <includes>
                <include>place.sh</include>
            </includes>
            <lineEnding>unix</lineEnding>
            <fileMode>0755</fileMode>
            <outputDirectory></outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

这是准备描述符

<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>prep-id</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>target/classes</directory>
            <outputDirectory></outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

我尝试运行 clean assembly:assembly,但我得到一个“未找到程序集描述符”错误

我尝试将我的插件重写为:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.5.5</version>
    <configuration>
        <finalName>my-project-2.0</finalName>
        <descriptors>
            <descriptor>src/assembly/bundle.xml</descriptor>
        </descriptors>
        <appendAssemblyId>false</appendAssemblyId>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <id>assemble</id>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

但我不知道如何将里面的zip命名为my-project.zip

【问题讨论】:

    标签: java xml maven


    【解决方案1】:

    使用prep.xml 创建压缩文件时,压缩文件的名称应为${project.artifactId}-${project.version}.zip

    所以在你的情况下是 my-project-${project.version}.zip。

    尝试通过以下方式编辑bundle.xml

    <fileSet>
      <directory>target</directory>
      <includes>
        <include>my-project-${project.version}.zip</include>
      </includes>
      <outputDirectory></outputDirectory>
    </fileSet>
    

    【讨论】:

      【解决方案2】:

      我的构建忽略描述符的主要原因是我的所有插件都包裹在 &lt;pluginManagement&gt; &lt;/pluginManagement&gt; 周围。

      这解决了我的问题

      【讨论】:

        猜你喜欢
        • 2018-07-04
        • 2020-12-26
        • 2010-12-19
        • 1970-01-01
        • 2015-04-14
        • 1970-01-01
        • 1970-01-01
        • 2013-04-03
        • 1970-01-01
        相关资源
        最近更新 更多