Search code examples
mavenmaven-assembly-plugin

How to include all files (not directories) in basedir of Maven assembly


In a maven assembly as shown below the result is recursion occurring re-including the base directory.

Following fails in fact consumes cpu and does not return:

<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>deploy</id>
  <baseDirectory>hive</baseDirectory>
    <includeBaseDirectory></includeBaseDirectory>
    <formats>
    <format>zip</format>
  </formats>
  <fileSets>
        <fileSet>
            <directory>${basedir}/lib</directory>
            <outputDirectory>lib</outputDirectory>
        </fileSet>
      <fileSet>
            <directory>${basedir}</directory>
            <outputDirectory></outputDirectory>
        </fileSet>
  </fileSets>
  <files>
    <file>
        <source>${basedir}/target/${project.build.finalName}.jar</source>
        <outputDirectory>lib</outputDirectory>
    </file>
  </files>
</assembly>

If instead the base directory were not included then the files under lib/* are properly included and the assembly is successful. So .. what is the proper syntax here? thanks!

Following builds an output zip but without the files in the base dir - so it is incomplete:

    <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>deploy</id>
  <baseDirectory>hive</baseDirectory>
    <includeBaseDirectory></includeBaseDirectory>
    <formats>
    <format>zip</format>
  </formats>
  <fileSets>
        <fileSet>
            <directory>${basedir}/lib</directory>
            <outputDirectory>lib</outputDirectory>
        </fileSet>
  </fileSets>
  <files>
    <file>
        <source>${basedir}/target/${project.build.finalName}.jar</source>
        <outputDirectory>lib</outputDirectory>
    </file>
  </files>
</assembly>

Solution

  • Here is a way to do this using include s with wildcards:

            <fileSet>
            <directory>${basedir}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.rb</include>
                <include>*.sh</include>
                <include>*.properties</include>
            </includes>
        </fileSet>