0

Is it possible to create a POM that, on package or greater, merely assembles the entire project (for example, into a zip file) and places it in target?

In this case, the project does not have any Java code in it, it is merely a set of scripts and files that I would like to have packaged. For the sake of uniformity (because our shop is all Maven), I would really like to have a POM do this, as, currently, we have a shell script doing it.

Examples would be MUCH appreciated.

Thanks

Cody S
  • 4,744
  • 8
  • 33
  • 64
  • Something like this? http://stackoverflow.com/q/1500758/422353 – madth3 Nov 08 '12 at 00:42
  • Yes, although, that's slightly more complex than what I was looking for. I'm about to post what I came up with myself (nice and simple). Thanks for the help though :) – Cody S Nov 08 '12 at 01:08

1 Answers1

2

So I ended up with the following, which creates a file ServerSetupTools-0.1-SNAPSHOT.tar.gz in target and that works for me. The only downside is that I wasn't sure how to get it to pull the files when they were in the root directory, so I moved them all to src/main/resources, which also worked for me. Hopefully this helps somebody else.

POM FILE:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>ServerSetupTools</artifactId>
<packaging>pom</packaging>
<name>ServerSetupTools</name>
<url>http://maven.apache.org</url>
<groupId>com.mycompany.utilities</groupId>
<version>0.1-SNAPSHOT</version>
<build>
    <plugins>
        <!--  Run assembly as part of packaging -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-5</version>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                    <descriptor>
                        src/main/assembly/assemble.xml
                    </descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase><!-- append to the packaging phase. -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

src/main/assembly/assemble.xml:

<assembly xmlns="http://maven.apache.org/xsd/assembly"
xsi:schemaLocation="http://maven.apache.org/xsd/assembly-1.0.0.xsd">
<id>dist</id>
<formats>
    <format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
    <fileSet>
        <includes>
            <include>*</include>
        </includes>
        <directory>src/main/resources</directory>
        <outputDirectory>bin</outputDirectory>
        <fileMode>0755</fileMode>
    </fileSet>
</fileSets>     

Cody S
  • 4,744
  • 8
  • 33
  • 64
  • 2
    You should stick to the [Maven Standard Directory Layout](http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html). That means that your scripts should be in `src/main/scripts` and not in `src/main/resources`. And you should not use the beta release of [`maven-assembly-plugin`](http://mvnrepository.com/artifact/org.apache.maven.plugins/maven-assembly-plugin/2.3), use version `2.3` which is the latest available. – maba Nov 08 '12 at 07:20
  • That's a great point. Unfortunately, the files contained in this project are not all scripts (there are some jars in there and whatnot). For the sake of simplicity (at the expense of organization), I'm gonna stick with `resources`. I'll switch to 2.3 per your advice – Cody S Nov 08 '12 at 16:54