春启动多模块项目



我有以下pom结构,

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc.xyz.parent</groupId>
<artifactId>parent</artifactId>
<version>0.1.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> 
<version>2.7.5</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<revision>0.1.0</revision>
<java.version>1.8</java.version>
<spring-boot.version>2.7.5</spring-boot.version>
<powermock.version>1.6.4</powermock.version>
<common-lib.version>${revision}</common-lib.version>
<maven-jacoco.version>0.8.6</maven-jacoco.version>
<maven-surefire.version>3.0.0</maven-surefire.version>
</properties>
<!-- To build everything properly use "mvn clean install -Pbuild" -->
<modules>        
<module>common-lib</module>
<module>my-service</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.abc.xyz.parent</groupId>
<artifactId>common-lib</artifactId>
<version>${common-lib.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

common-lib的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc.xyz.parent</groupId>
<artifactId>common-lib</artifactId>
<version>0.1.0</version>
<parent>
<groupId>com.abc.xyz.parent</groupId>
<artifactId>parent</artifactId>
<relativePath>../pom.xml</relativePath>
<version>0.1.0</version>
</parent>
<!-- 
Do not configure dependencies here (version, scope, exclusions, etc). Define them in a
central place, the dependency management in the root pom.
-->
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>       
</dependencies>
<build>
<plugins>
<plugin>    
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire.version}</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

和service pox.xml如下,

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>  
<artifactId>my-service</artifactId>
<version>0.1.0</version>
<parent>
<groupId>com.abc.xyz.parent</groupId>
<artifactId>parent</artifactId>
<relativePath>../pom.xml</relativePath>
<version>0.1.0</version>
</parent>
<!-- 
Do not configure dependencies here (version, scope, exclusions, etc). Define them in a
central place, the dependency management in the root pom.
-->
<dependencies>
<!-- All spring-boot dependencies requires omitted-->
<dependency>
<groupId>com.abc.xyz.parent</groupId>
<artifactId>common-lib</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${maven-jacoco.version}</version>
<executions>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire.version}</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<!-- <executable>true</executable> -->
</configuration>
</plugin>
</plugins>
</build>
</project>

我正在运行mvn包测试,在本地环境中一切正常,my-service.jar包含"common-lib";但是每当我尝试在Jenkins/CI中构建它时,我就会得到一个没有common-lib包装的my-service.jar,虽然在CI中编译也成功,但当我使用java.io.FileNotFoundException"运行应用程序时失败。例外。有人能解释一下这个配置有什么问题吗?

如上所述,我意外地运行了mvn package test而不是mvn test packagemvn package,这导致了这个错误。虽然我不确定为什么后来运行测试阶段搞砸了弹簧引导罐包装。我能够在本地环境中复制相同的。

最新更新