Havnar
Havnar

Reputation: 2628

Maven: Build tar.gz file with externally downloaded files

What I'm trying to do with maven is build a project.tar.gz file with some data in the ./data folder downloaded from some location on the web.

Currently I'm trying to approach this using the assembly plugin, so far without much success.

So far the following works: I download a file to target/data But now I need that file packaged in a tar file.

<build>
    <plugins>
        <plugin>
            <groupId>com.googlecode.maven-download-plugin</groupId>
            <artifactId>download-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>wget</goal>
                    </goals>
                    <configuration>
                        <url>http://www.lolcats.com/images/u/08/23/lolcatsdotcomcm90ebvhwphtzqvf.jpg</url>
                        <outputDirectory>${project.build.directory}/data</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Upvotes: 0

Views: 1649

Answers (2)

Havnar
Havnar

Reputation: 2628

I ended up using https://github.com/maven-download-plugin/maven-download-plugin

<build>
    <plugins>
        <plugin>
            <groupId>com.googlecode.maven-download-plugin</groupId>
            <artifactId>download-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>wget</goal>
                    </goals>
                    <configuration>
                        <url>${some.jar.file.url}</url>
                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        <url>${some.models.zip.url}</url>
                        <unpack>true</unpack>
                        <outputDirectory>${project.build.directory}/data</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-5</version> <!-- Old -->
            <executions>
                <execution>  <!-- Build tar.gz archive. -->
                    <id>tar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>src/tar.xml</descriptor>
                        </descriptors>
                        <finalName>project-${project.version}-el6</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                    </configuration>
                </execution>  <!-- /NewStuff -->
            </executions>
        </plugin>
    </plugins>
</build>

using tar.xml:

<assembly>
<id>tar</id>
<formats>
    <format>tar.gz</format>
</formats>
<fileSets>
    <fileSet>
        <directory>target/data</directory>
        <outputDirectory>/data</outputDirectory>
    </fileSet>
    <fileSet>
        <directory>target/lib</directory>
        <outputDirectory>/lib</outputDirectory>
    </fileSet>
    <fileSet>
        <directory>meta</directory>
        <outputDirectory>/meta</outputDirectory>
    </fileSet>
</fileSets>

Upvotes: 2

Aaron Digulla
Aaron Digulla

Reputation: 328574

I personally wouldn't use Maven for this; Maven is a tool for standard processes. What you want to do is very special.

Have a look at the Maven AntRun Plugin or use Ant directly. That way, you can create a script which does exactly what you want without fighting with Maven's conventions all the time.

Upvotes: 1

Related Questions