项目背景:需要使用甲方devops平台构建Java项目,但是我们项目中部分依赖存放于公司内部私有maven仓库,所以需要将这部分依赖使用本地导入,或者将这些依赖上传到客户私有仓库。
一、添加jar包到项目
在resource下新建lib目录(src/main/resources/lib),将需要添加的jar包上传到lib目录下。
二、在项目添加本地jar
先移除原pom依赖中对应的jar,再添加本地jar包,然后会显示本地路径的jar包
三、pom.xml配置修改
<dependency>
<groupId>com.iflytek.note</groupId>
<artifactId>iflydocs-pro-base</artifactId>
<version>1.0.1.RELEASE</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/lib/iflydocs-pro-base-1.0.1.RELEASE.jar</systemPath>
</dependency>
在dependency中添加jar包本地依赖路径
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/lib/iflydocs-pro-base-1.0.1.RELEASE.jar</systemPath>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
<mainClass>
com.iflytek.iflynote.fs.IflynoteFsApplication
</mainClass>
</configuration>
</plugin>
<!-- docker的maven插件,官网:https://github.com/spotify/docker‐maven‐plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<verbose>true</verbose>
<compilerArgs>
<compilerArg>
-parameters
</compilerArg>
</compilerArgs>
<compilerArguments>
<extdirs>${project.basedir}/src/main/resources/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
在maven plugin中添加相应配置
spring-boot-maven-plugin添加:
<includeSystemScope>true</includeSystemScope>
maven-compiler-plugin添加:
<compilerArguments>
<extdirs>${project.basedir}/src/main/resources/lib</extdirs>
</compilerArguments>