一、建立mvn-repo分支
首先在你的github上建立一个maven-repo-demo仓库,这个最后将做为实际上jar包发布的仓库git
二、设置真实姓名
在github的我的设置中,设置好本身的姓名 。这个环节很重要,若不设置姓名,会出现一些一些意想不到的错误,如:github
[ERROR] Failed to execute goal com.github.github:site-maven-plugin:0.12:site (default) on project rfcore: Error creating commit: Invalid request. [ERROR] For 'properties/name', nil is not a string. [ERROR] For 'properties/name', nil is not a string. (422) [ERROR] -> [Help 1]
一、设置本地maven的配置文件settings.xml,找到其中的servers 标签,加入以下 配置:apache
<server> <id>github</id> <username>*****</username> <password>*****</password> </server>
二、修改pom文件发布本地仓库
在须要发布的项目中的pom文件里的 标签下加入如下插件:maven
而后运行 mvn clean deploy 命令,便可在对应项目中的target/repository目录下找到本地的jarui
<build> <plugins> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.1</version> <configuration> <altDeploymentRepository>internal.repo::default::file://${project.build.directory}/repository</altDeploymentRepository> </configuration> </plugin> </plugins> </build>
一、修改pom文件,在properties 中添加下列属性插件
<properties> <github.global.server>github</github.global.server> </properties>
二、添加修改插件code
<build> <plugins> <!--打包插件--> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.1</version> <configuration> <altDeploymentRepository>internal.repo::default::file://${project.build.directory}/repository</altDeploymentRepository> </configuration> </plugin> <!--源码--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <!--github上传插件,用于修改后的发布,执行 mvn clean deploy 自动打包上传到github--> <plugin> <groupId>com.github.github</groupId> <artifactId>site-maven-plugin</artifactId> <version >0.12</version> <configuration> <message >Maven artifacts for ${project.version}</message> <noJekyll>true</noJekyll> <!--本地jar地址--> <outputDirectory>${project.build.directory}/repository</outputDirectory> <!--分支--> <branch>refs/heads/master</branch> <merge>true</merge> <includes> <include>**/*</include> </includes> <!--对应github上建立的仓库名称 name--> <repositoryName>maven-repo-demo</repositoryName> <!--github 仓库全部者 不是帐号--> <repositoryOwner>l305170891</repositoryOwner> </configuration> <executions> <execution> <goals> <goal>site</goal> </goals> <phase>deploy</phase> </execution> </executions> </plugin> </plugins> </build>
再次执行 mvn clean deploy命令便可发布到github上了 。
若出现以下错误请完成第一阶段第二步配置:server
[ERROR] Failed to execute goal com.github.github:site-maven-plugin:0.12:site (default) on project rfcore: Error creating commit: Invalid request. [ERROR] For 'properties/name', nil is not a string. [ERROR] For 'properties/name', nil is not a string. (422) [ERROR] -> [Help 1]
而后添加依赖便可xml
<dependency> <groupId>com.luojian.github.repo.demo</groupId> <artifactId>maven-repo-demo</artifactId> <version>1.0.1</version> </dependency>