NagyI
NagyI

Reputation: 5997

Generate distribution from Maven project

I want to build an application distribution with Maven. I have a module in my project which holds the main source code. I decided to build the application distribution from this module. I'm telling maven in the module's POM to copy all the configuration files and dependant libs to the target/ directory. My problem is that Maven keeps all the build related temporary dirs (like. classes, generated-sources, maven-archiver) in the target directory. I wan't to auto delete these at least during the install phase. How can i achive this? If i put the maven-clean-plugin to the end of the build it looks like Maven always deletes the whole target directory, no matter who i'm trying to exclude files what i'm trying to keep.

Upvotes: 2

Views: 6921

Answers (2)

Raghuram
Raghuram

Reputation: 52655

I'm telling maven in the module's POM to copy all the configuration files and dependant libs to the target/ directory

How are you doing this?

Based on the question, it looks like you need to worry less about selectively deleting contents of target folder (which can be done by customizing maven clean plugin), but creating a distribution using maven assembly plugin (as pointed out by @Scorpion).

The latter allows you to bundle together all your project artifacts including the dependencies into zip or other formats, which can then be easily used by developers. You may want to decouple this from regular build by using a separate profile, so that the distribution is built only on need basis.

Upvotes: 0

Scorpion
Scorpion

Reputation: 3986

try this in your pom

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-4</version>
    <executions>
        <execution>
            <id>user_distribution</id>
            <phase>package</phase>
            <goals>
                <goal>attached</goal>
            </goals>
            <configuration>
                <descriptors>
                    <descriptor>src/main/assembly/dist.xml</descriptor>
                </descriptors>
            </configuration>
        </execution>
    </executions>
</plugin>

and here is the xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/xsd/assembly-1.1.1.xsd">

    <id>dist</id>
    <formats>
        <format>zip</format>
    </formats>
    <files>
        <file>
            <source>target/${pom.artifactId}-${pom.version}.jar</source>
            <outputDirectory>lib/</outputDirectory>
        </file>
    </files>
    <fileSets>
        <fileSet>
            <directory>directory to be included</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>file name to be included</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>another directory to be included</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

Upvotes: 2

Related Questions