自定义jar包引入依赖传递
Overview
源于笔者想让自己打的jar包能引入jar包本身的其他依赖,而有此文。
生成jar包
目标结构
|-- [class files]
|-- META-INF
-- maven
-- <groupId>
-- <artifactId>
-- pom.propertis
-- pom.xml //项目pom.xml<pre>
pom.properties内容
version=<version>
groupId=<groupId>
artifactId=<artifactId>
pom.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>
<groupId>{project.groupId}</groupId>
<artifactId>{project.artifactId}</artifactId>
<version>{project.version}</version>
<dependencies>
<!-- 若干dependency -->
</dependencies>
</project>
使用maven安装jar包
mvn install:install-file -Dfile=<path-to-file>
P.S. 以上命令,仅限于maven默认 maven-install-plugin 版本为3.0.0-M1以上(含,官方有一处提及2.5.2也支持,笔者测试不支持,当时没怀疑被坑惨了),笔者撰写此文时,最新maven版本为 3.6.3,默认的 maven-install-plugin 版本为 2.4 ,因此,需要用如下命令:
mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=<path-to-file>
maven-install-plugin版本过低,将无法识别META-INF内的pom.xml,需要自己指定:
mvn install:install-file -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version> -Dfile=<path-to-file> -DpomFile=<path-to-pom>
P.S. 当指定-DpomFile时,jar包内无需META-INF(可删)
那么,该如何配置maven自带插件的默认版本呢?