【发布时间】:2017-01-05 11:21:06
【问题描述】:
有:
父 pom:
<groupId>practice</groupId>
<artifactId>app</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<modules>
<module>h2db</module>
</modules>
<build>
<pluginManagement>
...
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.185</version>
</dependency>
</dependencies>
儿童 pom:
<parent>
<artifactId>app</artifactId>
<groupId>practice</groupId>
<version>1.0</version>
</parent>
<artifactId>h2db</artifactId>
<build>
<finalName>h2db</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>h2_server.H2ConsoleServer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.185</version>
</dependency>
</dependencies>
在此示例中,这些是具有 2 个(或更多)依赖项的父 pom。子 pom 只有一个它需要的依赖项。我是否可以从这个子 pom 模块构建一个 jar 并包含 (scope:compile) 它的单一依赖项?它构建了一个 jar,但在 jar 文件中不包含 h2 依赖项。我尝试在子 pom 中使用 maven-assembly-plugin 和 jar-with-dependencies,但结果它创建了一个包含来自父 pom 的所有依赖项的 jar。
【问题讨论】: