GitHub建立个人Maven仓库

一、配置github

创建mvn-repo仓库

    首先在你的github上创建一个maven-repo仓库,这个最后将作为实际上jar包发布的仓库。

设置name

    在github的个人设置中,设置好自己的姓名 。这个环节很重要,若不设置姓名,会出现一些一些意想不到的错误。

二、配置部署jar到本地

修改mvn配置文件settings.xml

Win+R输入%MAVEN_HOME%打开maven安装目录,修改本地maven的配置文件settings.xml,找到其中的servers 标签,加入如下 配置:

<server>
    <id>github</id>
    <username>github登录名</username>
    <password>github登录密码</password>
</server>

修改pom文件发布到本地仓库

在需要发布的项目中的pom文件中的build -> pluginManagement -> plugins标签下加入以下插件:

<!--发布到本地仓库插件-->
<plugin>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.1</version>
    <configuration>
        <altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo</altDeploymentRepository>
    </configuration>
</plugin>

然后运行 mvn clean deploy 命令,即可在对应项目中的target/mvn-repo目录下找到本地的jar。

三、部署jar到github

修改pom文件properties中添加下列属性

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

添加远程发布插件

            <!--发布到服务器插件,需要依赖上面的部分-->
            <!--查看aliyun的仓库https://maven.aliyun.com/mvn/search,发现需要依赖包-->
            <plugin>
                <groupId>com.github.github</groupId>
                <artifactId>site-maven-plugin</artifactId>
                <version >0.9</version>
                <configuration>
                    <message >Maven artifacts for ${project.version}</message>
                    <noJekyll>true</noJekyll>
                    <outputDirectory>${project.build.directory}/mvn-repo</outputDirectory><!--本地jar地址-->
                    <branch>refs/heads/master</branch><!--branch必须是refs/heads/开头的,后边跟分支名称-->
                    <merge>true</merge>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <repositoryName>maven-repo</repositoryName> <!--对应github上创建的仓库名-->
                    <repositoryOwner>your setting name</repositoryOwner> <!--github仓库所有者setting中的name-->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>site</goal>
                        </goals>
                        <phase>deploy</phase>
                    </execution>
                </executions>
            </plugin>

依赖插件

        <!-- 发布到服务器插件的依赖包 -->
        <dependency>
            <groupId>com.github.github</groupId>
            <artifactId>site-maven-plugin</artifactId>
            <version>0.9</version>
            <type>maven-plugin</type>
        </dependency>

mvn clean deploy运行结果

四、使用github仓库

引用仓库

在需要使用jar包项目的pom文件中添加github仓库

    <!--引入仓库-->
    <repositories>
            <repository>
                <id>maven-repo-master</id>
                <url>https://raw.github.com/你的用户名/maven-repo/master/</url>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
            </repository>
    </repositories>

添加依赖

<dependency>
    <groupId>com.autumn</groupId>
    <artifactId>aeo-tool</artifactId>
    <version>1.0.0</version>
</dependency>

参考:https://www.jianshu.com/p/98a141701cc7

猜你喜欢

转载自www.cnblogs.com/aeolian/p/12444569.html