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

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

问题描述

假设我需要管理一个工件,该工件包含一个作为 zip 存档卷起的任意文件夹/文件结构.我不清楚如何以最适合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 中没有通用生命周期来简单地获取资源文件夹中的内容,将其压缩,然后将其安装/部署到我的存储库?

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?

我正在寻找选项,并评估每个选项如何满足我遵循 maven 方式的要求,因为我不希望招致偏离黄金路径的明显惩罚...

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 中填写如下内容:

Fill in assembly/sample.xml with something like this:

<?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天全站免登陆