【发布时间】:2011-12-31 07:00:48
【问题描述】:
我正在与 maven 斗争,通过使用 maven-assembly-plugin 将具有“提供”范围的托管依赖项包含到 tar 文件中。
我使用超级父 pom 文件作为我所有项目的基础。大多数项目将部署在应用程序服务器下,因此在超级父 pom 下声明了两个常见的依赖项。下面是父级的相关管理部分:
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx.integration</groupId>
<artifactId>super-parent</artifactId>
<packaging>pom</packaging>
<version>1.1.3</version>
<name>super parent</name>
<url>http://maven.apache.org.check</url>
.
.
.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
log4j.version=2.0.8
在一个继承的项目(它是一个独立的应用程序)中,我将 maven-assembly-plugin 与dependencySets 一起使用,以便将依赖库包含到一个 tar 文件中。当然,我还想包含 log4j 库。
下面是从父级继承的pom:
<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">
<parent>
<groupId>com.xxx.integration</groupId>
<artifactId>super-parent</artifactId>
<version>1.1.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>plugin-cc-checker</artifactId>
<name>plugin-cc-checker</name>
<version>2.1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.orca.integration</groupId>
<artifactId>integration-assembly-descriptor</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>make-assembly-according-to-distribution-xml</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>${artifactId}</finalName>
<!-- This is where we use our shared assembly descriptor -->
<descriptors>
<descriptor>distribution-app.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xerces</artifactId>
<version>${xerces.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
<version>${commons-logging-api.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>excalibur</groupId>
<artifactId>excalibur-i18n</artifactId>
<version>${excalibur-i18n.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
<version>${snmp4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
distribution-app.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<!-- Add module dependencies and the jar that is created in the packaging
phase. Product name will be <project name>-app-<version no>.tar -->
<id>app-${version}</id>
<formats>
<format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>resources/app</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<excludes>
<!-- Since there is a bug in xalan 2.7.1 all applications required to
use xalan-orca jar file -->
<exclude>xalan:xalan</exclude>
</excludes>
<!-- includes> <include>*</include> </includes-->
</dependencySet>
</dependencySets>
<moduleSets>
<moduleSet>
<binaries>
<outputDirectory>/guy</outputDirectory>
<includes>
<include>log4j:log4j</include>
</includes>
</binaries>
</moduleSet>
</moduleSets>
</assembly>
为什么 maven-assembly-plugin 拒绝将 log4j 包含到 tar 文件中? PS,尝试更改范围以进行编译也不起作用。我不能更改超级父 pom 中的声明。
【问题讨论】:
-
我可以看到子 pom 没有
versionfor log4j ?在这种情况下,它是否会从父级单独继承它并覆盖范围? -
它将继承其父 pom 的版本。无论如何我尝试添加版本,但它仍然没有任何区别。
标签: maven