使用github搭建个人Maven私服

准备

申请Github帐号并配置ssh public key: http://blog.youkuaiyun.com/psu_vjd/article/details/54317621

安装Git工具: http://blog.youkuaiyun.com/laiahu/article/details/7516939

安装Maven工具: http://blog.youkuaiyun.com/javaee_ssh/article/details/43774583

搭建过程

  1. 利用github网站中创建一个新的仓库,记下仓库地址:
    git@github.com:${github_account}/${maven-repo}.git
  2. 初始化git本地仓库,添加远端git仓库地址
    cd ${git_repo_path}
    git init
    git remote add origin git@github.com:${github_account}/${maven-repo}.git
  3. 创建.gitignore 并提交git本地仓库master分支
    echo "" >.gitignore
    git add -f .gitignore
    git commit -m 'add .gitignore' && git push origin master
  4. 创建分支snapshot并push到远程分支
    git branch snapshot
    git push origin snapshot
    git checkout snapshot
  5. 当开发完成后发布新的artifects(例如:${groupId}:${artifactId}:${version}),首先利用mvn deploy将artifects发布至刚刚创建的git仓库中
    mvn deploy -DaltDeploymentRepository=${distribute_id}::default::file:${git_repo_path}
    其中,${distribute_id}对应pom文件中distributionManagement/repository/id,也可随意填写
  6. 将需要发布对应版本的artifects提交至本地git仓库中,然后push至对应的分支snapshot 
    cd ${git_repo_path}
    git checkout snapshot
    git add -f ${groupId}/${artifactId}/${version}
    git commit -m 'deploy ${groupId}:${artifactId}:${version}'
    git push origin snapshot
  7. 在settings.xml中添加如下配置:
    <?xml version="1.0"?>
    <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">
    
    	<profiles>
    		<profile>
    			<id>${github_account}-github-maven</id>
    			<activation>
    				<activeByDefault>true</activeByDefault>
    				<jdk>1.7</jdk>
    			</activation>
    			<repositories>
    				<repository>
    					<id>${github_account}-maven-snapshot-repository</id>
    					<name>${github_account}-maven-snapshot-repository</name>
    					<url>https://raw.githubusercontent.com/${github_account}/${maven-repo}/snapshot</url>
    				</repository>
    			</repositories>
    		</profile>
    	</profiles>
    
    	<pluginGroups>
    		<pluginGroup>org.apache.maven.plugins</pluginGroup>
    	</pluginGroups>
    
    	<activeProfiles>
    		<activeProfile>${github_account}-github-maven</activeProfile>
    	</activeProfiles>
    
    </settings>
  8. 在pom.xml中使用上传的jar包:
    <dependencies>
    	<dependency>
    		<groupId>${groupId}</groupId>
    		<artifactId>${artifactId}</artifactId>
    		<version>${version}</version>
    	</dependency>
    </dependencies>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值