获取Maven exec:java插件以使用项目模块依赖项

时间:2009-09-30 11:14:33

标签: java maven-2 dependencies module

我正在使用Maven的exec:java为我的一个项目运行jline(下面附带当前的POM)。该项目曾经是一个组件,因此所有依赖项都与exec:java插件定义位于同一个POM中。这很好用,当我运行'mvn exec:java'时,所有依赖项都被选中并放在类路径上。但是,我现在将项目分成几个模块,并希望在exec:java运行时获取每个模块的依赖关系,但我无法弄清楚如何配置它。建议将不胜感激!

感谢, 尼克


<?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>

1 个答案:

答案 0 :(得分:2)

您可以为项目指定parent POM,并在父级的pluginManagement部分中定义exec-plugin。这意味着插件配置可用于声明最小插件配置的任何子POM。以下就足够了。

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

当处理子进程时,它将从父进程继承配置,并且将使用当前项目的依赖项执行exec-plugin。