Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any maven goal that is similar to 'dist'?

Tags:

maven-2

I'm working on a project that used ant. I had a target dist that would basically do jar first, and then install the application into a directory.

This means, it would create directories like bin/, lib/ and config/ in the installation directory, and then copy the relevant files into each of these directories.

My question is two-fold:

  1. Is there any maven goal that does this kind of thing?
  2. If not, I want to do maven dist and make this happen. How would you suggest I accomplish this using Maven?
  3. If I can't have my own "target" (like dist), then what would be the best way?

Bottom line: I want to do all this, but don't want to alter the behavior of the default "targets" like compile and package etc.

Thanks, jrh

PS: I'm using maven version 2.2.21

like image 481
jrharshath Avatar asked Nov 22 '10 13:11

jrharshath


People also ask

What are the different goals in Maven?

Here are some of the phases and default goals bound to them: compiler:compile – the compile goal from the compiler plugin is bound to the compile phase. compiler:testCompile is bound to the test-compile phase. surefire:test is bound to the test phase.

How do I run a specific goal in Maven?

Run a Maven goal from the context menu In the Maven tool window, click Lifecycle to open a list of Maven goals. Right-click the desired goal and from the context menu select Run 'name of the goal'. IntelliJ IDEA runs the specified goal and adds it to the Run Configurations node.

Is Maven a clean goal?

Maven clean goal (clean:clean) is bound to the clean phase in the clean lifecycle. Its clean:cleangoal deletes the output of a build by deleting the build directory. Thus, when mvn clean command executes, Maven deletes the build directory.

What is Maven project goal?

Maven goals represent a specific task that contributes to the building and managing of a project. Sometimes, a maven goal is not bound to a build phase. We can execute these goals through the command line.


1 Answers

I don't know what would go in config, but lib and bin is easy.

To copy all dependencies to a folder just do this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>
                ${project.build.directory}/dist/lib
                </outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

To output your jar to a bin folder do this (reference page):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <finalName>${project.artifactId}</finalName>
        <outputDirectory>${project.build.directory}/dist/bin</outputDirectory>
    </configuration>
</plugin>

Ah, there are additional requirements:

Bottom line: I want to do all this, but don't want to alter the behavior of the default "targets" like compile and package etc.

In this case I'd use a profile to turn this on:

<profile>
    <id>dist</profile>
    <build>
        <plugins>
            <!-- insert stuff from above here -->
        </plugins>
    </build>
</profile>

Now you would do mvn clean package -Pdist to get your dist directory and if you don't add the profile, you get default behaviour.

Basically, things work differently in maven from the way they do in ant. There are no targets, there are only lifecycle phases and plugin goals.

You can either execute a lifecycle phase, which will call all maven plugin goals that are bound to all phases up to this one (e.g. if you do mvn compile, the following phases will be executed: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile). But there is no (easy) way to define a lifecycle phase named dist.

Or you can execute a specific plugin goal (you can actually execute multiple phases and / or plugin goals). E.g. you could write your own dist plugin and call it using mvn dist:dist, but I wouldn't recommend that because you are using existing functionality and the profile solution should be a pretty good fit.

like image 135
Sean Patrick Floyd Avatar answered Oct 03 '22 23:10

Sean Patrick Floyd