Maven: release single file, set line endings

2.1k Views Asked by At

I would like to release single file to Nexus repo (deploy script, sh) and for that purpose I am using

build-helper-maven-plugin:attach-artifact

Unlike Maven Assembly Plugin, it hasn't explicit option to set line ending of the deployed file. How can I solve the task using this or other plugin.

Important: I need file deployed as .sh and not as archive. Otherwise it's possible to switch to Maven Assembly Plugin.

2

There are 2 best solutions below

1
On BEST ANSWER

The maven-assembly-plugin has a format dir which is simply a folder structure on the hard drive which you can use to copy the sh script to that folder and convert linenendings and use build-helper-maven-plugin to attach that artifact afterwards.

0
On

Let me share final solution. I hope it would help someone one day...

pom.xml

<build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptors>
                        <descriptor>deploy-script-assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>deploy-script-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.9</version>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${build.directory}/${project.artifactId}-${project.version}-single/deploy-script.sh</file>
                                    <type>sh</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
...
</plugins>
</build>

deploy-script-assembly.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

    <id>single</id>

    <formats>
        <format>dir</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

    <files>
        <file>
            <source>deploy-script.sh</source>
            <outputDirectory>/</outputDirectory>
            <lineEnding>unix</lineEnding>
        </file>
    </files>

</assembly>