Java – Maven assembly plugin chmod output folder

javamavenmaven-assembly-plugin

I am trying to use the maven-assembly plugin like so to build a zip of my project JAR and all libraries needed to run it:

        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
<descriptor>src/main/assembly/exportWithDepends.xml</descriptor>
                            </descriptors>
                            <finalName>myname</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

My assembly looks like:

<assembly>
    <id>jar-with-dependencies</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <unpack>false</unpack>
            <scope>runtime</scope>
            <outputDirectory>lib</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <fileMode>755</fileMode>
        </dependencySet>
    </dependencySets>
    <files>
        <file>  
<source>${project.build.directory}/${project.build.finalName}.jar</source>
        </file>
    </files>
</assembly>

This works and makes the proper zip.

Then the fileMode flag on the dependencySet gives each element inside of LIB a 755 CHMOD. The problem is, the actual LIB folder itself stays 777. Is there a way to make the LIB folder also get a 755?

Making maven do things it doesn't want to do always makes me sad 🙁

Best Answer

This is really weird, but following snippet of pom.xml will set 0755 mode to all directories of assembly. Though, I think this isn't very reliable (future-proof), as, obviously, maven authors intended to use well-known Unix octal notation to specify directory access mode, not decimal equivalent.

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <archiverConfig>
                    <!-- 493D == 0755, seems to be assembly plugin bug -->
                    <defaultDirectoryMode>493</defaultDirectoryMode>
                </archiverConfig>
            </configuration>

Original credit must go here: https://issues.apache.org/jira/browse/MASSEMBLY-494

Related Topic