我有2个Eclipse项目:(1)my-library
,该项目构建my-library-1.0.jar
;和(2)my-deployable
,生成my-deployable-1.0.war
。
my-library
是的中列出的依赖pom.xml
项my-deployable
。
my-library
在中引用了2个依赖项(2个Apache Commons JAR)pom.xml
。
my-library
已注册到我的Nexus,并且可以检索它。
当我my-deployable-1.0.war
使用Goals进行构建时clean compile package
,my-library-1.0.jar
包含在WEB-INF\lib
文件夹中,但是预期的WAR中没有包含它的2个依赖项。我的印象是,我不需要在pom.xml
of中明确指定它们,my-deployable
因为它们已在pom.xml
of中列出my-library
。
为什么在构建WAR时不将my-library
JAR的依赖项包含在my-deployable
WAR中?
该pom.xml
用于my-library
读取:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my</groupId>
<artifactId>my-library</artifactId>
<version>1.0</version>
<name>My Library</name>
<description>This is my library JAR. It will be included in my WAR.</description>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.17</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
</build>
</project>
该pom.xml
用于my-deployable
读取:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.12.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.my</groupId>
<artifactId>my-deployable</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>My Deployable</name>
<description>A deployable WAR for Spring Boot that has a dependency of my-library</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.my</groupId>
<artifactId>my-library</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
当JAR注册到内部Nexus存储库中(此任务移交给第二小组)时,pom.xml
分配给它的是Sonatype Nexus生成的pom.xml
,而不是JAR附带的。生成的文件没有关联的依赖项。
生成的无效pom.xml
类似于:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my</groupId>
<artifactId>my-library</artifactId>
<version>1.0</version>
<description>POM was created by Sonatype Nexus</description>
</project>
我通过检查pom.xml
Nexus中的每个JAR并将其与每个.m2文件夹和每个项目中的JAR进行比较,发现了这一点;我pom.xml
用相关项目中的文件对.m2 进行了硬交换,构建了我的WAR,并出现了传递性依赖项。
下一步是使用正确的修复所有Nexus条目pom.xml
。