Mig*_*uel 113 java maven-2 pom.xml
可以通过<exclusions>
在a中声明一个元素来排除依赖项中的工件.<dependency>
但在这种情况下,需要排除从父项目继承的工件.正在讨论的POM摘录如下:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>jruby</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>ALL-DEPS</artifactId>
<version>1.0</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
base
工件,取决于 javax.mail:mail-1.4.jar
,并ALL-DEPS
取决于同一个库的另一个版本.由于这样的事实mail.jar
,从ALL-DEPS
存在于执行环境,虽然没有出口,碰撞与mail.jar
那对父母,这是作用域确定为存在compile
.
解决方案可能是从父POM中删除mail.jar,但是大多数继承base的项目都需要它(因为它是log4j的转换依赖项).所以我想做的是简单地从子项目中排除父项库,因为如果base
是依赖项而不是父项pom 可以这样做:
...
<dependency>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<type>pom<type>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>
...
Run Code Online (Sandbox Code Playgroud)
Pas*_*ent 46
一些想法:
在这种情况下,也许你根本不能从父级继承(并且base
通过排除声明依赖).如果父母pom中有很多东西,那就不方便了.
要测试的另一件事是使用父pom 下的mail
所需版本声明工件以强制收敛(虽然我不确定这将解决范围问题).ALL-DEPS
dependencyManagement
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>???</version><!-- put the "right" version here -->
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
mail
从log4j中排除依赖,如果你没有使用依赖它的功能(这就是我要做的):<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)
tim*_*nen 24
您可以使用pom
Sonatypes Best Practices所描述的包装将您的依赖项分组到不同的项目中:
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>base-dependencies</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
并从您的父pom引用它们(观察依赖关系<type>pom</type>
):
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<artifactId>base-dependencies</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
你的子项目像以前一样继承了这个父pom.但现在,可以在dependencyManagement
块中的子项目中排除邮件依赖项:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>jruby</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<artifactId>base-dependencies</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Run Code Online (Sandbox Code Playgroud)
使用scope
系统指向空jar 重新定义依赖项(在子pom中):
<dependency>
<groupId>dependency.coming</groupId>
<artifactId>from.parent</artifactId>
<version>0</version>
<scope>system</scope>
<systemPath>${project.basedir}/empty.jar</systemPath>
</dependency>
Run Code Online (Sandbox Code Playgroud)
该jar只能包含一个空文件:
touch empty.txt
jar cvf empty.txt
Run Code Online (Sandbox Code Playgroud)
这可能听起来很极端,但同样的方式"继承地狱"是一些人背弃面向对象编程的原因,或者外科医生通过冠状动脉搭桥手术让你活着的同样方式:删除有问题的<parent>
块并复制并粘贴<dependencies>
你需要的任何东西.
假设将poms分成父母和孩子以"重用"和"避免冗余"应该被忽略,你应该首先满足你的直接需求.冗余有其优点 - 即外部并发症的独立性.
如果您生成有效的pom(eclipse提供它但您可以从命令行生成它),这比听起来更容易.
我想使用,mvn help:effective
但我的父pom使用logback
,我不想去,必须将其他孩子对log4j的依赖推入他们自己的log4j
文件,以便我的通畅.
你可以从父母那里得到很多,但有时你的父母不知道什么对你有好处.
您是否尝试过明确声明所需的mail.jar版本?Maven的依赖项解析应该使用它来解决所有其他版本的依赖项解析.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>jruby</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>VERSION-#</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>ALL-DEPS</artifactId>
<version>1.0</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
小智 5
在子 pom.xml 中重复父级的依赖项并在其中插入排除:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
113183 次 |
最近记录: |