將自定義jar包上傳github並制作成maven倉庫


參照:https://www.jianshu.com/p/98a141701cc7

第一階段 :配置github

1、創建mvn-repo分支    
首先在你的github上創建一個maven-repo-demo倉庫,這個最后將作為實際上jar包發布的倉庫

2、設置真實姓名    
在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]

第二階段:配置部署jar到本地1、 配置本地mvn服務

1、設置本地maven的配置文件settings.xml,找到其中的servers 標簽,加入如下 配置:

        <server>
            <id>github</id>
            <username>*****</username>
            <password>*****</password>
        </server>

2、修改pom文件發布本地倉庫   
在需要發布的項目中的pom文件里的 標簽下加入以下插件:

然后運行 mvn clean deploy 命令,即可在對應項目中的target/repository目錄下找到本地的jar

        <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>

第三階段:發布jar到遠程github上

1、修改pom文件,在properties 中添加下列屬性

        <properties>
            <github.global.server>github</github.global.server>
        </properties>

2、添加修改插件

        <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上了 。
若出現如下錯誤請完成第一階段第二步配置:

    [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]

第四階段:在項目中使用發布到github上的jar包pom文件中添加github倉庫

然后添加依賴即可

        <dependency>
            <groupId>com.luojian.github.repo.demo</groupId>
            <artifactId>maven-repo-demo</artifactId>
            <version>1.0.1</version>
        </dependency>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM