Search code examples
javalinuxmavenmaven-3maven-assembly-plugin

Use Maven assembly plugin to set Linux file permissions for specific files


How to set file permission for specific files using Maven assembly plugin?

The following works ok but it only includes the specificShFile.sh in the assembled archive:

<assembly>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>${project.build.outputDirectory}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>specificShFile.sh</include>
            </includes>
            <fileMode>0755</fileMode>
        </fileSet>
        ...
    </fileSets>
    ...
</assembly>

What I want is all files to be included in the zip but permission to be set only to that specific file.


Solution

  • Many thanks to @SubOptimal for his hint, here is the solution that worked for me:

    <assembly>
        <formats>
            <format>zip</format>
        </formats>
        <fileSets>
            <fileSet>
                <directory>${project.build.outputDirectory}</directory>
                <outputDirectory>/</outputDirectory>
                <excludes>
                    <exclude>specificShFile.sh</exclude>
                </excludes>
            </fileSet>
            <fileSet>
                <directory>${project.build.outputDirectory}</directory>
                <outputDirectory>/</outputDirectory>
                <includes>
                    <include>specificShFile.sh</include>
                </includes>
                <fileMode>0755</fileMode>
            </fileSet>
            ...
        </fileSets>
        ...
    </assembly>