How to save executable file permissions in maven archetype

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

How can I tell maven to save permissions to execute these files? Or maybe it makes sense to tell maven to automatically add execution permissions on generation?

+5
source share
3 answers

I decided a similar version with exec-maven-plugin with two executions, one of them is zip directories, and the other is deployed using the bin classifier in the repository in my case to a third party. Therefore, I saved all unix permissions in a 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>

, "bin":

<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>
+1

, , , . , groovy script archetype-post-generate.groovy src/main/resources/META-INF/ . script :

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

request.getOutputDirectory() - , , request.getArtifactId() - .

+1

. maven script Linux Windows

, , :

            <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 for this for every installation, and not just for generating archetypes, therefore, if someone has any better suggestions, they would like to hear them.

0
source

All Articles