I have an external groovy script that i need to include in a zip file by means of the maven assembly plugin.
I can't just compile it, it needs to be in text-form. The problem i am facing is that the script contains æ ø å characters, and that is causing some problems. The script itself runs file from its place in the maven project, but when i package it with the maven assembly plugin, and then unzip it, its non ascii characters are corrupted. The script also runs fine if i use 7zip or the like to zip and unzip it, no corruption happens.
How can i tell the maven assembly plugin to conserve my special characters? I would really hate to have to make a lot of changes to the code in order to convert it to a maven project.
Here is a part of my pom
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<encoding>UTF-8</encoding>
<descriptors>
<descriptor>src/main/assembly/archive.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
and my Descriptor
<id>archive</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
...
<fileSet>
<lineEnding>unix</lineEnding>
<directory>src/main/groovy</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>BusinessServiceMock.groovy</include>
</includes>
</fileSet>
...
I had the same problem, after 3 hours of deep searching. I found another alternative of using maven-antrun-plugin instead of maven-assembly-plugin because it simply does not propose encoding for file name inside zip archive.
Here is my solution:
1.Firstly, to ensure that file names are in UTF-8 encoding for example, I copy my ressource to project build repository and force input and output encoding.
2.Then i create my zip by adding the copied target directory.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>prepare-package</phase>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<tasks>
<copy todir="${project.build.directory}/target"
includeemptydirs="true"
encoding="${project.build.sourceEncoding}"
outputencoding="${project.build.sourceEncoding}">
<fileset dir="${basedir}/src/resource">
<include name="**/*" />
</fileset>
</copy>
<zip destfile="${project.build.directory}/${project.artifactId}-${project.version}.zip"
encoding="${project.build.sourceEncoding}">
<zipfileset dir="${project.build.directory}/target" includes="**" />
</zip>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
To ensure that the encoding is ok you can use maven-enforcer-plugin to check subfolder and files encoding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With