创建临时zip工件的Maven最佳实践 [英] Maven best practice for creating ad hoc zip artifact

查看:71
本文介绍了创建临时zip工件的Maven最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我需要管理一个工件,该工件由一个作为zip档案卷起来的aribtrary文件夹/文件结构组成.我尚不清楚如何以最适合"Maven方式"的方式在Maven中完成此操作.

Assume that I need to manage an artifact that consists of an aribtrary folder / file structure rolled up as a zip archive. It's not clear to me how to accomplish this in Maven in a way that best fits "the Maven way."

我知道没有"zip"包装类型.这是否意味着Maven中没有通用生命周期可以简单地将我在resources文件夹中拥有的内容压缩,压缩并安装/部署到我的存储库中?

I know that there is no "zip" packaging type. Does this mean there is no generic lifecycle in Maven to simply take what I have in the resources folder, zip it up, and install/deploy it to my repositories?

我正在寻找期权,并评估每个期权如何满足我遵循行家的要求,因为我不希望招致明显的违背黄金之路的惩罚. . .

I'm looking for options, with evaluations of how each option satisifies my requirement to follow the maven way, as I do not wish to incur the obvious penalities of straying from the golden path . . .

推荐答案

确定用于您的zip文件的分类器,出于争论的目的,假设它是sample.

Decide what classifier you will use for your zip file, for sake of argument let's say it would be sample.

在您的项目中创建文件assembly/sample.xml

In your project create file assembly/sample.xml

用以下内容填充assembly/sample.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>sample</id>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <outputDirectory>/</outputDirectory>
      <directory>some/directory/in/your/project</directory>
    </fileSet>
  </fileSets>
  <!-- use this section if you want to package dependencies -->
  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory>
      <excludes>
        <exclude>*:pom</exclude>
      </excludes>
      <useStrictFiltering>true</useStrictFiltering>
      <useProjectArtifact>false</useProjectArtifact>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>

将此添加到pom的build部分

Add this to your pom's build section

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>create-distribution</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>assembly/sample.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

因此,它应该创建并安装you-project-name-VERSION-sample.zip.

As a result it should create and install you-project-name-VERSION-sample.zip.

我建议您阅读Sonatype的Maven书中有关装配的章节: https://books.sonatype.com/mvnref-book/reference/assemblies.html

I suggest you read chapter on assemblies from Sonatype's maven book: https://books.sonatype.com/mvnref-book/reference/assemblies.html

也请阅读汇编格式规范: http://maven.apache .org/plugins/maven-assembly-plugin/assembly.html

Also, read assembly format specification: http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

这篇关于创建临时zip工件的Maven最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆