Java – Getting Maven exec:java plugin to use project module dependencies

dependenciesjavamaven-2module

I'm using Maven's exec:java to run jline for one of my projects (current POM attached below). The project used to be a single component, so all dependencies were in the same POM as the exec:java plugin definition. This worked great and all the dependencies were picked up and put on the classpath when I ran 'mvn exec:java'. However, I've now split up the project into a few modules and would like the dependencies from each module to be picked up when exec:java is run, but I can't figure out how to configure it. Advice would be greatly appreciated!

thanks,
Nick


<?xml version="1.0" encoding="UTF-8"?>
<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>
    <name>Lensfield</name>
    <groupId>org.lensfield</groupId>
    <artifactId>lensfield-pom</artifactId>
    <version>0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includeProjectDependencies>true</includeProjectDependencies>
                    <includePluginDependencies>true</includePluginDependencies>
                    <executableDependency>
                        <groupId>jline</groupId>
                        <artifactId>jline</artifactId>
                    </executableDependency>
                    <mainClass>jline.ConsoleRunner</mainClass>
                    <arguments>
                        <argument>clojure.lang.Repl</argument>
                    </arguments>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>jline</groupId>
                        <artifactId>jline</artifactId>
                        <version>0.9.94</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
    <modules>
        <module>lensfield-share</module>
        <module>lensfield-build</module>
        <module>lensfield-webapp</module>
    </modules>
</project>

Best Solution

You can specify a parent POM for the project and define the exec-plugin in the pluginManagement section of the parent. This means that the plugin configuration will be available to any child POM that declares a minimal plugin configuration. The following would be sufficient.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
</plugin>

When the child is processed it will inherit the configuration from the parent, and the exec-plugin will be executed with the current project's dependencies.