我正在使用 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>
最佳答案
您可以指定 parent POM为项目定义 exec-plugin pluginManagement
parent 的部分。这意味着插件配置将可用于任何声明最小插件配置的子 POM。以下内容就足够了。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</plugin>
当子进程被处理时,它将继承父进程的配置,exec-plugin 将使用当前项目的依赖项执行。
关于java - 获取 Maven exec :java plugin to use project module dependencies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1497494/