20

Similar question: Can Ant's tar task set a Linux file permission even when the task is used on other platforms?

If I use Maven 2 assembly plugin with the 'project' descriptor, is there a way to set shell script permissions to executable for example for included build.sh script files?

Example:

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>project</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>

This will create three files

  • -project.tar.bz2
  • -project.tar.gz
  • -project-zip

And I would like to set the file permissions for all *.sh files which are in the tar files to 'executable'.

Community
  • 1
  • 1
mjn
  • 36,362
  • 28
  • 176
  • 378

2 Answers2

53

This can be done using the fileMode parameter available in Maven Assembly Plugin assembly descriptor. For instance

<assembly>
    ...
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/bin</directory>
            <outputDirectory>/bin</outputDirectory>
            <includes>
                <include>*.sh</include>
            </includes>
            <fileMode>0755</fileMode>
        </fileSet>
        ...
    </fileSets>
    ...
</assembly>
Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • How does it works if I compile my plugin Eclipse RCp with Tycho? Where do I need to write this files? I've only some pomx.xml file...Is there a "fileMode" with Tycho? – user376112 Feb 15 '11 at 16:49
  • It sets me bin/ directory to d--------- permissions :\. The files inside are ok. – Alfonso Nishikawa Jun 02 '17 at 11:14
  • This creates the tar with files having 775 permission with all the directories (folders) dont have even read permission (d--------). What should be done for this? – Saurabhcdt Sep 19 '17 at 09:25
4

It was asked in comments how to set permisions for directories, so that they don't end up with d--------- permissions. The answer is pretty straightforward - use directoryMode:

<assembly>
    ...
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/bin</directory>
            <outputDirectory>/bin</outputDirectory>
            <includes>
                <include>*.sh</include>
            </includes>
            <fileMode>0755</fileMode>
            <directoryMode>0755</directoryMode>
        </fileSet>
        ...
    </fileSets>
    ...
</assembly>
doryDev
  • 41
  • 3