【问题标题】:Maven creating flat zip assemblyMaven 创建平面 zip 程序集
【发布时间】:2010-12-02 19:31:14
【问题描述】:

致 Maven 大师: 我正在尝试将非 Java 项目工件 (.NET) 打包到单个 zip 文件中。我有两个问题:

如果我将 POM 中的包装更改为 zip <packaging>zip</packaging>,我会收到以下错误消息:[INFO] Cannot find lifecycle mapping for packaging: 'zip'. Component descriptor cannot be found in the component repository: org.apache.mav en.lifecycle.mapping.LifecycleMappingzip. 好的,没什么大不了的 - 我将其更改为 <packaging>pom</packaging> 以摆脱在目标目录

我的主要问题是我打包到 ZIP 中的文件嵌套在几个目录中,但我需要将它们放入 ZIP 的顶级目录中。这是我的汇编文件:

 <assembly>
  <id>bin</id>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${basedir}/${project.artifactId}</directory>
      <includes>
        <include>**/Bin/Release/*.dll</include>
        <include>**/Bin/Release/*.pdb</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>

当我运行它时 - 我会得到 ZIP 文件,但文件将从 C:\ 开始嵌套,后跟完整路径。给你一个想法 - 项目将它的二进制文件转储到以下结构中 ProjectFoo\ProjectFoo\subproject1\Bin\Release\foo.dll 我需要ZIP\foo.dll

这里是汇编插件配置:

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
    <descriptors>
        <descriptor>assembly.xml</descriptor>
    </descriptors>
</configuration>
<executions>
    <execution>
        <id>zip</id>
        <phase>package</phase>
        <goals>
            <goal>single</goal>
        </goals>
    </execution>
</executions>

也许我只需要使用 antrun 并执行 ant zip 任务?

【问题讨论】:

    标签: maven-2 assemblies zip


    【解决方案1】:

    正如您所见,没有 zip 包装类型,因此按照您的选择使用 pom 包装是有意义的。

    您在程序集插件的处理过程中遇到了一些漏洞。您可以通过在程序集中使用&lt;outputDirectory&gt;/&lt;outputDirectory&gt; 指定多个文件集来解决此问题,每个目录对应一个您要包含的目录,这显然是一个 PITA,可能不是一个可接受的解决方案。

    另一种方法是使用 Ant 复制任务将所有 DLL 复制到暂存目录中,然后将该目录包含在程序集中。

    以下配置应该可以满足您的需求:

    antrun-plugin 配置:

      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <phase>process-resources</phase>
            <configuration>
              <tasks>
                <copy todir="${project.build.directory}/dll-staging">
                  <fileset dir="${basedir}/${project.artifactId}">
                    <include name="**/Bin/Release/*.dll"/>
                    <include name="**/Bin/Release/*.pdb"/>
                  </fileset>
                  <flattenmapper/>
                </copy>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    

    大会:

     <assembly>
      <id>bin</id>
      <formats>
        <format>zip</format>
      </formats>
      <fileSets>
        <fileSet>
          <directory>${project.build.directory}/dll-staging</directory>
          <outputDirectory>/</outputDirectory>
          <includes>
            <include>*.dll</include>
            <include>*.pdb</include>
          </includes>
        </fileSet>
      </fileSets>
    </assembly>
    

    【讨论】:

    • 还有一个问题。 zip 仍然维护一个“artifactId-Version”类型的顶级目录。当我提取 zip 文件时,我的所有文件最终都不是在 / 中,而是在 /Foo-1.0-SNAPSHOT/ 中。然而文件被正确复制到目标/dll-staging
    • 实际上 - 将&lt;includeBaseDirectory&gt;false&lt;/includeBaseDirectory&gt; 放入汇编中就可以了
    • (感谢您在这里保存我们的培根 - 不错!)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    相关资源
    最近更新 更多