首页 文章

Maven创造平拉链组件

提问于
浏览
20

对于那里的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> 以摆脱在目标目录中创建的无用jar

我的主要问题是我打包成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>

当我运行这个 - 我'll get ZIP file but files will be nested starting with C:\ followed by full path. To give you idea - project dumps it'的二进制文件到以下结构 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任务?

1 回答

  • 28

    如您所见,没有拉链包装类型,因此您可以选择使用pom包装 .

    你've encountered a bit of a hole in the assembly plugin'正在处理 . 您可以通过在程序集中使用 <outputDirectory>/<outputDirectory> 指定多个fileSets来解决此问题,每个目录对应一个PIT,这可能不是一个可接受的解决方案 .

    另一种方法是使用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>
    

相关问题