Search code examples
javamavenmaven-assembly-plugin

Generated files are not copied into Maven project zip with the Assembly Plugin


A Java code created some files, and it internally tried to copy into zip. But all files copied except some files. I am not able to find out the reason behind this.

I am adding directory structure of folder that I tried to copy with its permissions and what exactly it copied in target folder (zip file).

Directory structure and its permissions -


XYZ-MacBook-Pro:etl_configs XYZ$ pwd
FILE_PATH_LOCATION/etl_configs

XYZ-MacBook-Pro:etl_configs XYZ$ ls -l *
-rw-r--r--  1 XYZ  staff   980 Jun 26 01:02 etl-spec.json
-rwxr-xr-x  1 XYZ  staff  2037 Jun 15 19:04 etl-without-transformation.json

feeds:
total 16
-rw-r--r--  1 XYZ  staff  612 Jun 26 00:54 feed_1.json
-rw-r--r--  1 XYZ  staff  616 Jun 26 01:02 feed_2.json

tables:
total 16
-rw-r--r--  1 XYZ  staff  878 Jun 26 00:54 table_1.json
-rw-r--r--  1 XYZ  staff  880 Jun 26 01:02 table_2.json

Trying to copy all these files in zip using maven plugins.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.5.5</version>
    <configuration>
        <descriptor>${project.basedir}/zip.xml</descriptor>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

zip.xml file contains -

<fileSet>
        <directory>${project.basedir}/etl_configs</directory>
        <outputDirectory>/etl_configs</outputDirectory>
        <includes>
                <include>*</include>
        </includes>
</fileSet>

Target zip file contains-

XYZ-MacBook-Pro:etl-without-transformation-template-1.0-SNAPSHOT XYZ$ pwd
FILE_PATH_LOCATION/target/etl-without-transformation-template-1.0-SNAPSHOT-zip/etl-without-transformation-template-1.0-SNAPSHOT 
XYZ-MacBook-Pro:etl-without-transformation-template-1.0-SNAPSHOT XYZ$ ls -l etl_configs/*
-rwxr-xr-x  1 XYZ  staff   980 Jun 26 01:02 etl_configs/etl-spec.json
-rwxr-xr-x  1 XYZ  staff  2037 Jun 15 19:04 etl_configs/etl-without-transformation.json

etl_configs/feeds:

etl_configs/tables:

Ideally it should copy the entire folder inside zip. But it is not happening.


Solution

  • The issue related to the way you are using <includes> inside your assembly descriptor. You currently use

    <fileSet>
        <directory>${project.basedir}/etl_configs</directory>
        <outputDirectory>/etl_configs</outputDirectory>
        <includes>
            <include>*</include>
        </includes>
    </fileSet>
    

    which means: "Include all files under etl_configs". This does not mean "Include all files recursively under etl_configs". This is because you are using <include>*</include>: the maven-assembly-plugin uses Ant-style patterns, and, in Ant, * matches zero or more characters within a path name, not crossing directory boundaries.

    As such, to include recursively all files, you could use:

    <fileSet>
        <directory>${project.basedir}/etl_configs</directory>
        <outputDirectory>/etl_configs</outputDirectory>
        <includes>
            <include>**</include>
        </includes>
    </fileSet>
    

    But, this is the default behaviour:

    When <include> subelements are present, they define a set of files and directory to include. If none is present, then <includes> represents all valid values.

    So you can just have:

    <fileSet>
        <directory>${project.basedir}/etl_configs</directory>
        <outputDirectory>/etl_configs</outputDirectory>
    </fileSet>