【问题标题】:Maven dependency unpack - skip top level directoryMaven依赖解包 - 跳过顶级目录
【发布时间】:2019-08-27 18:00:42
【问题描述】:

我们有一个工件,它是我们想要解压的第三方 zip 文件,并将解压后的结构包含在我们自己的程序集中。

问题是解压后的 zip 文件的顶层目录是一个丑陋的目录名,其中包含一堆版本信息。在我们的最终程序集中,我们只想将解压后的结构放在一个简单的目录名下。

我们希望解包“跳过”顶级目录,或者我们希望程序集能够通过通配符指定文件集的顶级目录,或者我们需要一个构建步骤(antrun 插件?)来重命名它顶级目录 - 再次,通过通配符 - 进入一致的东西。

谷歌搜索表明在 regexp 类型中添加 a 可以让我重写文件名,但显然 maven 程序集插件不支持(自然)。

【问题讨论】:

    标签: maven maven-assembly-plugin maven-dependency-plugin


    【解决方案1】:

    我想通了。

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.8</version>
      <executions>
        <execution>
          <id>copy</id>
          <phase>package</phase>
          <configuration>
            <tasks>
              <copy todir="${project.build.directory}/dependency/simple_name">
                <fileset dir="${project.build.directory}/dependency"/>
                <regexpmapper from="^prefix[^/]*/(.*)$$" to="\1"/>
              </copy>
            </tasks>
          </configuration>
          <goals><goal>run</goal></goals>
        </execution>
      </executions>
    </plugin>
    

    这会将解压缩的内容从复杂目录复制到一个简单目录中。这有点浪费,因为它留下了复杂的结构,但我不在乎。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      • 2023-03-05
      • 2015-01-16
      • 1970-01-01
      相关资源
      最近更新 更多