Maven使用GitHub项目目录搭建远程仓库

使用GtiHub的项目目录搭建第三方远程仓库,能免除使用服务器搭建Nexus私服,而且空间也是免费的。但是这种方式只适合小规模发布,毕竟搜索和版本控制是一个问题,如果需要更复杂的功能就只能转向Nexus这样的私服。

搭建步骤如下:

1、配置POM发布到本地目录,配置如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.jsoft</groupId>
    <artifactId>testcommon</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>testcommon</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <distributionManagement>
        <repository>
            <id>jsoftlocal-mvn-repo</id>
            <url>file:D:/jsoftlocal-mvn-repo/</url>
        </repository>
    </distributionManagement>

</project>

提示:url节点中,Linux目录配置参考:file:/user/home/test/;其实<distributionManagement>节点可以发布到远程,也就是http地址,也可以发布到本地目录,就如上面配置一样。

2、使用deploy插件进行发布,命令行:

mvn deploy

插件官网:http://maven.apache.org/plugins/maven-deploy-plugin/

3、发布好之后的文件如下所示:

目录上使用包的目录一层一层的,最后这些文件全部上传到GitHub目录。

3、上传到GitHub目录,比如我将上面的文件夹上传到我新建的项目目录,如下所示:

https://github.com/easonjim/5_java_example/tree/master/mavenrepository/jsoftlocal-mvn-repo/

当然,也可以直接上传如上目录的全部文件到指定的项目目录即可,重点是上面的文件。

4、获取GitHub的资源路径,比如上面的项目路对应的资源路径就只是域名不同。地址如下:

https://raw.githubusercontent.com/easonjim/5_java_example/master/mavenrepository/jsoftlocal-mvn-repo/

注意:这个目录是GitHub安全机制导致不能浏览,但这一些放在POM上是正常运作的。

也可以通过下载jar包测试是否通,地址如下:

https://raw.githubusercontent.com/easonjim/5_java_example/master/mavenrepository/jsoftlocal-mvn-repo/com/jsoft/testcommon/0.0.1-SNAPSHOT/testcommon-0.0.1-20170617.163808-1.jar

5、配置项目使用上传的JAR包,POM配置如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.jsoft</groupId>
    <artifactId>usetestcommon</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>usetestcommon</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>jsoftlocal-mvn-repo</id>
            <url>https://raw.githubusercontent.com/easonjim/5_java_example/master/mavenrepository/jsoftlocal-mvn-repo/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jsoft</groupId>
            <artifactId>testcommon</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

先配置远程仓库地址,其中url节点就是第4步所获得的地址;JAR包的依赖按平时引入即可。

提示:远程仓库节点中的url可以配置http地址,也可以配置本地局域网地址,还可以配置本地目录地址,只要这个目录包含了第3步中所示的JAR包的依赖文件即可。本地目录地址参考:file:D:/jsoftlocal-mvn-repo/,注意前缀file。

测试工程:https://github.com/easonjim/5_java_example/tree/master/mavenrepository

参考:

http://www.importnew.com/22992.html 

原文地址:https://www.cnblogs.com/EasonJim/p/7043341.html