如何使用';提供';maven汇编插件的作用域
我正在与maven进行斗争,通过使用maven程序集插件将具有“提供”作用域的托管依赖项包含到tar文件中 我使用超级父pom文件作为我所有项目的基础。大多数项目将部署在ApplicationServer下,因此在超级父pom下声明了两个常见的依赖项。下面是超级母公司的相关管理部分:如何使用';提供';maven汇编插件的作用域,maven,Maven,我正在与maven进行斗争,通过使用maven程序集插件将具有“提供”作用域的托管依赖项包含到tar文件中 我使用超级父pom文件作为我所有项目的基础。大多数项目将部署在ApplicationServer下,因此在超级父pom下声明了两个常见的依赖项。下面是超级母公司的相关管理部分: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<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>
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
com.xxx.com集成
超级父母
聚甲醛
1.1.3
超级父母
http://maven.apache.org.check
.
.
.
朱尼特
朱尼特
${junit.version}
测试
log4j
log4j
${log4j.version}
假如
log4j.version=2.0.8
在一个继承的项目(这是一个独立的应用程序)中,我使用maven assembly plugin和dependencySets,以便将依赖库包含到一个tar文件中
以下是从超级父级继承的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>
com.xxx.com集成
超级父母
1.1.3
4.0.0
插件cc检查器
插件cc检查器
2.1
maven汇编插件
com.orca.integration
集成程序集描述符
1.1.1
根据分发xml进行组装
包裹
单一的
${artifactId}
distribution-app.xml
薛西斯
薛西斯
${xerces.version}
运行时
公用记录
通用日志api
${commons logging api.version}
运行时
神剑
神剑-i18n
${excalibur-i18n.version}
运行时
org.snmp4j
snmp4j
${snmp4j.version}
运行时
log4j
log4j
运行时
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>
应用程序-${version}
焦油
假的
资源/应用程序
/
/解放党
沙兰:沙兰
/家伙
log4j:log4j
为什么maven汇编插件拒绝将log4j包含到tar文件中?
PS,尝试将作用域更改为编译也不起作用。我无法更改超级父pom中的声明。无法在maven中重写“提供的”作用域 为了解决这个问题,我在父pom中声明了一个变量,该变量将定义工件作用域。为了覆盖作用域,唯一需要做的事情是在继承的pom中为变量设置新值 见下例: 父pom:
<properties>
<log4j.version>1.2.8</log4j.version>
<log4j.scope>provided</log4j.scope>
</properties>
.
.
.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>${log4j.scope}</scope>
</dependency>
</dependencies>
</dependencyManagement>
1.2.8
假如
.
.
.
log4j
log4j
${log4j.version}
${log4j.scope}
现在在子pom中,只需再次声明变量:
<properties>
<log4j.scope>runtime</log4j.scope>
</properties>
运行时
您可以简单地将范围定义到您的项目中。我遇到了一个类似的问题,试图将项目与范围为“提供”的依赖项组合在一起。
我找到了解决此问题的方法:
- 将依赖项保留在“提供的”范围内
- 使用maven dependency插件()将依赖项复制到目标文件夹
- 使用程序集描述符中的文件集将依赖项捆绑为文件
assembly.xml
:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
<dependencySet>
<unpack>true</unpack>
<scope>provided</scope>
</dependencySet>
</dependencySets>
</assembly>
这将创建一个yourproject-bin.jar,其中包含所有编译和提供的资源,以便在类路径中引用它们
java -cp yourproject-bin.jar com.yourcompany.Main
您可以通过在希望覆盖托管依赖项的POM中的
标记内声明它来覆盖托管依赖项
在您的情况下,您应该将以下内容添加到您的孩子pom中:
<dependencyManagement>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>provided</scope>
</dependency>
</dependencyManagement>
log4j
log4j
${log4j.version}
假如
请注意,这将覆盖父POM的依赖项管理中声明的所有内容,即,您不能不声明
版本
或范围
而期望它被继承。我可以看到子POM在log4j中没有版本
?在这种情况下,它是否单独从父POM继承该版本,范围过大?它将我从它的父pom继承了这个版本。我尝试添加这个版本,但仍然没有任何区别。我尝试使用程序集描述符,但它根本不起作用。不管怎样。你使用的是哪个版本的Maven和哪个版本的Maven程序集插件?Maven版本是3.0.3,Maven程序集插件没有版本事实上,maven 3.0.3在super pom中特别使用了maven assembly插件的2.2-beta-5版本,如果没有被覆盖的话。它有一个部分包含antrun的版本,如下所示
<dependencyManagement>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>provided</scope>
</dependency>
</dependencyManagement>