5

I am producing an artifact named foo.bar.zip from the following...

My pom.xml plug-in entry looks like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <descriptor>src/assembly/bin.xml</descriptor>
        <finalName>foo.bar</finalName>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
        </execution>
    </executions>
</plugin> 

My descriptor file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<formats>
    <format>zip</format>
</formats>
<fileSets>

etc. etc. 

My question, is how do I produce a file with a custom extension? E.g. with the name foo.bar instead of foo.bar.zip.

bn.
  • 7,739
  • 7
  • 39
  • 54
  • You can't. And this use-case is _really_ bizarre. Why would you want to package a ZIP with a `bar` extension? Maven won't let you do that. – Tunaki Apr 21 '16 at 18:31
  • 1
    @tunaki, the file extension is expected by a third-party application. – bn. Apr 21 '16 at 19:46
  • What do you mean? Can you tell more about your use-case? What problem are you trying to solve? – Tunaki Apr 21 '16 at 19:47
  • 2
    @tunkai, it is pretty straight forward -- the third-party application has a proprietary file extension instead of just using requiring .zip. I'm trying to make what is a really a .zip file build as a .zip file with a custom extension. – bn. Apr 21 '16 at 19:50
  • You could try that, never tested http://stackoverflow.com/questions/18969880/maven-output-jar-with-arbitrary-extension – Tunaki Apr 21 '16 at 19:56

2 Answers2

5

I solved this by combining:

  1. maven-assembly-plugin
  2. copy-rename-maven-plugin
  3. build-helper-maven-plugin

The assembly plugin has a configuration option to not attach the file, so I do that:

<configuration>
    ...
    <attach>false</attach>
</configuration>

Then I use the copy-rename-maven-plugin to rename the file, produced by assembly-plugin, from zip to my custom file type (in my case it is CLI).

After that I use build-helper-maven-plugin to attach the artifact with the custom file type.

Tomas Bjerre
  • 3,270
  • 22
  • 27
1

Assembly supports just these formats:

"zip" - Creates a ZIP file format

"tar" - Creates a TAR format

"tar.gz" or "tgz" - Creates a gzip'd TAR format

"tar.bz2" or "tbz2" - Creates a bzip'd TAR format

"jar" - Creates a JAR format

"dir" - Creates an exploded directory format

"war" - Creates a WAR format

You should consider to use antrun plugin in a later goal/phase to rename file extension

Community
  • 1
  • 1