Creating a tar.gz archive with Maven

后端 未结 2 1656
长情又很酷
长情又很酷 2021-02-19 07:51

I have a Maven project, where under src/main directory there is a sub dir called output. this folder needs to be packaged into tar.gz. when using the assembly plugin as follows:

相关标签:
2条回答
  • 2021-02-19 07:55

    You need to configure the assembly descriptor to not include the base directory and to configure an output directory for the fileSet:

    <assembly>
      <id>bundle</id>
      <formats>
        <format>tar.gz</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <fileSets>
        <fileSet>
          <directory>src/main/output</directory>
          <outputDirectory>output</outputDirectory>
        </fileSet>
      </fileSets>
    </assembly>
    

    With the above assembly descriptor, I get the following result (when running on a project reproducing the structure):

    $ mvn clean assembly:assembly
    ...
    $ cd target
    $ tar zxvf Q3330855-1.0-SNAPSHOT-bundle.tar.gz 
    output/
    output/hello.txt
    

    See also

    • The Assembly Descriptor Format reference
    0 讨论(0)
  • 2021-02-19 08:13

    Try setting outputDirectory in the fileSet. That should remove the src/main/output directories.

    <fileSet>
      <directory>src/main/output</directory>
      <outputDirectory>.</outputDirectory>
    </fileSet>
    

    You may also need to set includeBaseDirectory to false. That would remove the name directory.

    <assembly>
      <id>bundle</id> 
      <includeBaseDirectory>false</includeBaseDirectory>
      <!-- ... -->
    
    0 讨论(0)
提交回复
热议问题