文章目录
- Maven
- 环境
- deploy
- release
- Repo Manager
- 演示
- Ref
- FAQ
Maven
环境
- jdk8
- maven v3.9.5
deploy
mvn install
将jar存到localRepository
,mvn deploy
把jar推送到远程仓库,然后可以像central
库那样下载依赖。
release
基于git执行项目发版流程,版本号升级、git打标签、deploy。
见maven release
Repo Manager
演示选用dzikoysk/reposilite作为仓库管理器,使用单体jar版本启动,方便快捷
下载后在控制台执行如下
java -Xmx100m -jar repo.jar
启动log完毕后,输入help
查看交互式指令来设置管理器,同时http://localhost:8080
可访问,是仓库的UI界面
回到jar启动完毕结尾处,服务会响应输入的指令
token-generate admin m --secret=123456
route-add admin / rw
分别输入执行以上两行指令后,基本配置完毕
演示
- 项目基本结构
<artifactId>release-test</artifactId> <version>1.0.3-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>sub-module-1</module> </modules>
- maven上下文配置如下
-
settings.xml
<server> <!-- Id has to match the id provided in pom.xml --> <id>my-domain-repository</id> <username>admin</username> <password>123456</password> </server>
这里usename 、password就是上文指令配置的token 用户和secret密码,即admin和123456
-
pom.xml
<distributionManagement> <repository> <id>my-domain-repository</id> <url>http://localhost:8080/releases</url> </repository> <snapshotRepository> <id>my-domain-repository</id> <url>http://localhost:8080/snapshots</url> </snapshotRepository> </distributionManagement>
注意id要与
settings.xml
的server id一致。
-
deploy验证
做完前两步,在pom.xml所在目录执行mvn deploy
,没有错误的话,打开前文提到的UI页面,根据pom配置的打包版本是snapshot还是release的,本项目version
是SNAPSHOT,从页面进入snapshots仓库可找到构件。如下图
-
release验证
按照上文提到的release-plugin,在pom层级开始命令行。mvn -B clean release:prepare -DdryRun=true mvn -B release:prepare -DskipTests=true -DpushChanges=false mvn -B release:perform -DlocalCheckout=true
在release的操作试验中,
git tag -l
查看maven执行过程中给git仓库打的标签,每一个release对应一个tag。命令汇总
mvn -B clean release:prepare -DskipTests=true -DpushChanges=false release:perform -DlocalCheckout=true
结果如下(摘取部分)
输出
[INFO] [INFO] — deploy:3.1.1:deploy (default-deploy) @ release-test —
[INFO] [INFO] Uploading to my-domain-repository: http://localhost:8080/releases/org/test/learn/release-test/1.0.3/release-test-1.0.3.pom
[INFO] [INFO] Uploaded to my-domain-repository: http://localhost:8080/releases/org/test/learn/release-test/1.0.3/release-test-1.0.3.pom (1.4 kB at 7.2 kB/s)
[INFO] [INFO] Downloading from my-domain-repository: http://localhost:8080/releases/org/test/learn/release-test/maven-metadata.xml
[INFO] [INFO] Uploading to my-domain-repository: http://localhost:8080/releases/org/test/learn/release-test/maven-metadata.xml
[INFO] [INFO] Uploaded to my-domain-repository: http://localhost:8080/releases/org/test/learn/release-test/maven-metadata.xml (306 B at 8.7 kB/s)查看仓库,已在release库中
-
引用验证
已将构件部署到远程仓库中,现测试依赖导入是否能找到
用sub-module-1
测试,因在release过程中install
到本地仓库,需要删除本地的来验证后续。下图所示,要删除
创建新maven项目,添加以下配置到pom
- 添加repo
<repositories> <repository> <id>my-domain-repository</id> <url>http://localhost:8080/release</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <dependencies> <dependency> <groupId>org.test.learn</groupId> <artifactId>sub-module-1</artifactId> <version>1.0.3</version> </dependency> </dependencies>
- 测试
mvn clean compile
可以看到从仓库找到并下载sub-module-1
,说明仓库可引用可部署
- 添加repo
Ref
repository
distributionManagement
release-plugin
deploy-plugin
scm
FAQ
- Repo Manager 未配置token
会有如下错误
reason phrase: unauthorized - 其他的Repo Manager未测试,应该都大差不差