使用mvn dependency:unpack解压tar.gz到正确的路径。

问题描述 投票:0回答:1

在Maven构建中,我想下载并解压keycloak的tar.gz发行版。

以下是我的相关配置 maven-dependency-plugin:

<execution>
  <id>unpack-keycloak</id>
  <goals>
    <goal>unpack</goal>
  </goals>
  <phase>generate-resources</phase>
  <configuration>
    <artifactItems>
      <artifactItem>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-server-dist</artifactId>
        <version>${keycloak.version}</version>
        <type>tar.gz</type>
        <outputDirectory>/opt/jboss/keycloak</outputDirectory>
        <includes>**/*</includes>
      </artifactItem>
    </artifactItems>
  </configuration>
</execution>

不幸的是,这导致存档被解压到 optjbosskeycloakkeycloak-10.0.1 而不是 optjbosskeycloak 。有什么办法可以让我摆脱中间目录吗?

显然,我知道很多解压后移动存档的方法,但我想在这个执行中寻找一个解决方案,因为我有同一个插件的后续执行,希望分发已经正确到位。

maven maven-dependency-plugin
1个回答
1
投票

来自文档。https:/maven.apache.orgpluginsmaven-dependency-pluginexamplesunpacking-filemapper.html。

见第21-26行

编辑自OP。 这是正确的答案,但由于文档并不明显,这里有一个工作配置。

  <execution>
    <id>unpack-keycloak</id>
    <goals>
      <goal>unpack</goal>
    </goals>
    <phase>generate-resources</phase>
    <configuration>
      <artifactItems>
        <artifactItem>
          <groupId>org.keycloak</groupId>
          <artifactId>keycloak-server-dist</artifactId>
          <version>${keycloak.version}</version>
          <type>tar.gz</type>
          <outputDirectory>/opt/jboss/keycloak</outputDirectory>
          <includes>**/*</includes>
          <fileMappers>
            <org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
              <pattern>^\Qkeycloak-${keycloak.version}/\E</pattern>
              <replacement>./</replacement>
            </org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
          </fileMappers>
        </artifactItem>
      </artifactItems>
    </configuration>
  </execution>
© www.soinside.com 2019 - 2024. All rights reserved.