一、建立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>