项目引入第三方lib是比较常见的,本地编译往往不会有太大问题,因为可以将lib加入到编译路径中。但是,如果集成了cicd,devops环境中的maven插件编译项目时,会发生找不到lib包里的类的错误。因此需要将lib引入到pom中。
<dependency> <groupId>com.xx.x.xx</groupId> <artifactId>xx.xx</artifactId> <version>3.0.1</version> <scope>system</scope> <systemPath>${project.basedir}/lib/x-x-x-3.0.1.jar</systemPath> </dependency>
1. jar的坐标取值于jar包本身的pom文件,在META-INF下的pom文件中。
2. <scope>system</scope> 表示引入第三方jar包
3. <systemPath>是jar包所在路径
至此,项目就可以在cicd流程中编译成功。但值得注意的是,jar包并没有打入到package里,运行时仍会报错。需要再进行一项配置:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>