使用GIT 仓库作为个人maven-仓库地址(gitee)

本文介绍如何配置Maven项目的仓库设置,包括本地仓库、远程仓库的添加及更新策略,并提供Windows环境下部署脚本示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

新建项目名称为 maven-repository
git账号添加ssh-key 官方文档地址http://git.mydoc.io/?t=154712
pom文件添加
 <repositories><!-- 代码库 -->
        <repository>
            <id>git-maven</id>
            <url>“自己的maven仓库地址”</url>
        </repository>
        <repository>
            <id>maven-ali</id>
            <url>http://maven.aliyun.com/nexus/content/groups/public//</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
            </snapshots>
        </repository>
    </repositories>
    <distributionManagement>
        <repository>
            <id>nexus</id>
            <url>file:${user.home}/git/maven-repository/repository/</url>
        </repository>
        <snapshotRepository>
            <id>nexus</id>
            <url>file:${user.home}/git/maven-repository/repository/</url>
        </snapshotRepository>
    </distributionManagement>
添加deploy 文件 (以windows脚本为例)
@echo off
set "GITSSH=自己的git地址"
set "PROJECTJAR=项目文件中的版本路径(eg:com\fetus\version\version-parent\v1.0.0-SNAPSHOT)"
set "GITDIR=git\maven-repository"
del /S /F /Q %USERPROFILE%\%GITDIR%\*.*
rd /Q /S   %USERPROFILE%\%GITDIR%\
mkdir %USERPROFILE%\%GITDIR%
git init %USERPROFILE%\%GITDIR%
c:
cd %USERPROFILE%\%GITDIR%
git  remote  add origin %GITSSH%
git pull origin master
del /S /F /Q %USERPROFILE%\%GITDIR%\repository\%PROJECTJAR%\*.*
rd /Q /S    %USERPROFILE%\%GITDIR%\repository\%PROJECTJAR%\
%~d0
cd %~dp0
call mvn deploy
c:
cd %USERPROFILE%\%GITDIR%
git add -A
git add -u
git add .
git commit -a -m "update version-parent"
git push origin master
%~d0
cd %~dp0
### 获取代码并构建项目 #### 准备工作 为了确保能够顺利从 Gitee 仓库获取代码并使用 Maven 进行构建,需确认 Java 和 Maven 的版本以及环境配置正确无误。当前环境中使用的 Java 版本为 "1.8.0_181",Maven 版本为 3.6.3,这与 Spring Boot 2.x 是兼容的[^1]。 #### 克隆 Git 仓库 要从 Gitee 上拉取项目的最新源码,可以通过命令行工具 git 来完成此操作: ```bash git clone https://gitee.com/your-repository-url.git cd your-project-directory ``` 上述命令中的 `https://gitee.com/your-repository-url.git` 应替换为目标仓库的实际 URL 地址;而 `your-project-directory` 则是指定本地保存该项目目录的位置名称。 #### 使用 Maven 打包项目 进入项目根目录之后,通过执行如下命令来利用 Maven 对整个工程进行打包: ```bash mvn clean package -DskipTests=true ``` 这条指令的作用在于清理旧的目标文件夹(`clean`),接着按照 pom 文件定义的方式编译和测试应用程序(`package`),同时跳过单元测试部分(-DskipTests=true),以加快构建过程的速度。 如果遇到依赖项下载失败的情况,则可能是因为国内网络访问中央仓库速度较慢所致。此时可以在 `$HOME/.m2/settings.xml` 中添加阿里云镜像服务器作为代理,从而提高资源加载效率[^2]: ```xml <mirrors> <mirror> <id>aliyun</id> <name>Aliyun Mirror</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> ``` 成功执行以上步骤后,应该能够在目标路径下找到生成好的 jar 或 war 文件,这意味着已经完成了基于 Gitee 源码库并通过 Maven 工具链实现自动化构建的任务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值