一、安装本地Maven仓库
mvn install:install-file \
--settings /Users/xxx/.m2/settings.xml \
-Dfile=C:\x-x-cache-0.1.0-SNAPSHOT.jar \
-DgroupId={com.x.x.x} \
-DartifactId={x-x-cache} \
-Dversion={0.1.0-SNAPSHOT} \
-Dpackaging=jar
-s :指定配置文件
二、发布Jar到远程仓库
# jar
mvn deploy:deploy-file \
--settings /Users/xxx/.m2/settings.xml \
-Dmaven.test.skip=true \
-Dfile=C:\xiaxinyu\x-x-cache-0.1.0-SNAPSHOT.jar \
-DpomFile=xxx-xx-xx-0.1.0-SNAPSHOT.pom \
-DgroupId={com.x.x.x}\
-DartifactId={x-x-cache} \
-Dversion={0.1.0-SNAPSHOT} \
-Dpackaging=jar \
-DrepositoryId={itlab} \
-Durl={http://x.x.x.x:8081/repository/maven-snapshots/}
# pom
mvn deploy:deploy-file \
--settings /Users/xxx/.m2/settings.xml \
-Dmaven.test.skip=true \
-Dfile=xxx-xx-xx-0.1.0-SNAPSHOT.pom \
-DpomFile=xxx-xx-xx-0.1.0-SNAPSHOT.pom \
-DgroupId={com.x.x.x}\
-DartifactId={x-x-cache} \
-Dversion={0.1.0-SNAPSHOT} \
-Dpackaging=pom\
-DrepositoryId={itlab} \
-Durl={http://x.x.x.x:8081/repository/maven-snapshots/}
注意:{}中的参数需要根据自身实际情况进行修改
三、settings.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/Users/xxx/.m2/</localRepository>
<servers>
<server>
<username>xinyu.xia</username>
<password>NN5xP6jenc</password>
<id>itLab</id>
</server>
</servers>
<mirrors>
</mirrors>
<profiles>
<profile>
<repositories>
<!--包含需要连接到远程仓库的信息 -->
<repository>
<!--远程仓库唯一标识 -->
<id>itLab</id>
<!--远程仓库名称 -->
<name>itLab maven</name>
<!--如何处理远程仓库里发布版本的下载 -->
<releases>
<!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
<enabled>true</enabled>
<!--该元素指定更新发生的频率。Maven会比较本地POM和远程POM的时间戳。这里的选项是:always(一直),daily(默认,每日),interval:X(这里X是以分钟为单位的时间间隔),或者never(从不)。 -->
<updatePolicy>always</updatePolicy>
<!--当Maven验证构件校验文件失败时该怎么做-ignore(忽略),fail(失败),或者warn(警告)。 -->
<checksumPolicy>ignore</checksumPolicy>
</releases>
<!--如何处理远程仓库里快照版本的下载。有了releases和snapshots这两组配置,POM就可以在每个单独的仓库中,为每种类型的构件采取不同的策略。例如,可能有人会决定只为开发目的开启对快照版本下载的支持。参见repositories/repository/releases元素 -->
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
<!--远程仓库URL,按protocol://hostname/path形式 -->
<url>http://xxx:40286/repository/maven-public/</url>
<!--用于定位和排序构件的仓库布局类型-可以是default(默认)或者legacy(遗留)。Maven 2为其仓库提供了一个默认的布局;然而,Maven 1.x有一种不同的布局。我们可以使用该元素指定布局是default(默认)还是legacy(遗留)。 -->
<layout>default</layout>
</repository>
</repositories>
</profile>
</profiles>
</settings>
注意:需要保持DrepositoryId、server/id、repository/id需要保持id一致