9

I am building an archetype where I want to include a folder with some executable binaries. The problem is that when I create a new project from the archetype, the executable binaries are created without executable permissions.

How can I tell maven to keep execute permissions on those files ? Or maybe there is a mean to tell maven to add execute permissions automatically at generation time ?

baraber
  • 3,296
  • 27
  • 46

3 Answers3

9

This question is quite old, but I found myself in the same situation and I found a solution, so here it goes. Here it says that you can write a groovy script named archetype-post-generate.groovy in the src/main/resources/META-INF/ folder of your archetype in order to perform actions after the new project has been generated. The script should look like this one:

def file = new File( request.getOutputDirectory(), request.getArtifactId()+"RELATIVE_PATH" );
file.setExecutable(true, false);

where request.getOutputDirectory() is the directory where the new project will be created and request.getArtifactId() is the project artifact id.

1

I solved similar isue with exec-maven-plugin with two executions, one is zip the directorys and the other deploy with a bin classifier to the repository in my case to the third-party. So I saved all unix permissions in the zip file.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>1</id>
            <phase>package</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>zip</executable>
                <workingDirectory>${basedir}</workingDirectory>
                <arguments>
                    <argument>-r</argument>
                    <argument>target/com.example.test.ext.zip</argument>
                    <argument>Out</argument>
                    <argument>-x</argument>
                    <argument>*.svn*</argument>
                </arguments>
            </configuration>
        </execution>
        <execution>
            <id>2</id>
            <phase>package</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>mvn</executable>
                <workingDirectory>${basedir}/target</workingDirectory>
                <arguments>
                    <argument>deploy:deploy-file</argument>
                    <argument>-Dfile=com.example.test.ext.zip</argument>
                    <argument>-Dclassifier=bin</argument>
                    <argument>-DgroupId=com.example</argument>
                    <argument>-DartifactId=test</argument>
                    <argument>-Dversion=1.0</argument>
                    <argument>-Dpackaging=zip</argument>
                    <argument>-DrepositoryId=releases</argument>
                    <argument>-Durl=http://nexus..../nexus/content/repositories/thirdparty
                    </argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

If you use the result as a depenency dont forget the "bin" classifier:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.8</version>
    <executions>
        <execution>
            <id>unpack1</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>com.example</groupId>
                        <artifactId>test</artifactId>
                        <version>1.0-SNAPSHOT</version>
                        <classifier>bin</classifier>
                        <type>zip</type>
                        <overWrite>true</overWrite>
                        <outputDirectory>output</outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>
aberes
  • 297
  • 1
  • 6
0

See this post for another example maven calls external script on both Linux and Windows platforms

So I worked round this by adding the following:

            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>script-chmod</id>
                    <phase>install</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>chmod</executable>
                        <arguments>
                            <argument>+x</argument>
                            <argument>myscript</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

However, this seems wasteful running this for each install rather than just on archetype generation so if anyone has any better suggestions then would love to hear them.

Community
  • 1
  • 1
Martin Matthews
  • 686
  • 6
  • 3