记一次 Centos7 Nexus 配置私服(Maven私服)

第一部分   环境搭建

详见:https://blog.csdn.net/llwy1428/article/details/99537867

第二部分   Nexus 配置

一、仓库的创建及发布私有 Jar 包到本地仓库

1、创建仓库

2、创建宿主仓库

说明:

group:仓库组,项目直接引用的仓库;

hosted:项目自己创建的仓库,自己上传jar包,默认有开发库(开发阶段用)和线上仓库(项目上线时用);

proxy:远程引用仓库。

3、创建 release 仓库,仓库名称 hunter-release (名字自定义), type选择 : release

4、创建 snapshot 仓库,仓库名称 hunter-snapshot (名字自定义), type选择 : snapshot

5、创建结果

说明:

maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar

maven-releases:私库发行版jar (上线时用)

maven-snapshots:私库快照(调试版本,开发时用)jar

maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。

6、配置本地 Maven 的 settings.xml 配置文件添加如下信息:

代码如下

<server>
    <id>hunter-realease</id>
    <username>admin</username>
    <password>admin123</password>
</server>
<server>
    <id>hunter-snapshot</id>
    <username>admin</username>
    <password>admin123</password>
</server>

7、基本配置

(1)IDEA 中配置 JDK1.8 (略);

(2)IDEA 中配置 Maven (略);

(3)打开 IDEA  创建项目(项目创建过程:略)。

8、配置项目的 pom.xml 文件

    <distributionManagement>
        <repository>
            <id>hunter-release</id>
            <name>Release Repository of Hunter</name>
            <url>http://192.168.11.16:8081/repository/hunter-release/</url>
        </repository>
        <snapshotRepository>
            <id>hunter-snapshot</id>
            <name>Snapshot Repository of Hunter</name>
            <url>http://192.168.11.16:8081/repository/hunter-snapshot/</url>
        </snapshotRepository>
    </distributionManagement>

注意:<distributionManagement></distributionManagement> 中的 id 要和 Maven settings.xml 中 server 中配置的 id 要一一对应。

8、编写测试工具类,打包发布到本地仓库

编写完代码后,先执行 1(clean)  再执行 2(deploy),  见下图右侧:

/**
 * String 工具类
 */
public class HunterStringUtil {
    /**
     * 如果被判断的值是 null 则返回指定的字符串
     * @param obj
     * @param str
     * @return String
     */
    public static String emptyToString(Object obj,String str){
        return obj==null?"":obj.toString();
    }
}

执行结果

9、现在去 Nexus web 中查看本地仓库

至此,把本地项目打包发布到本地仓库,操作完毕!

二、创建远程仓库、仓库组及其使用

1、创建阿里云远程仓库

创建结果

2、创建自定义仓库组(把所有的仓库加入自定义仓库组-可自主选择)

创建结果

3、测试本地仓库组

打开 IDEA  创建项目(项目创建过程:略)

配置项目的 pom.xml 文件

    <repositories>
        <repository>
            <id>nexus-admin</id>
            <name>nexus-admin Repository</name>
            <url>http://192.168.11.16:8081/repository/nexus-admin/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus-admin</id>
            <name>nexus-admin Repositories</name>
            <url>http://192.168.11.16:8081/repository/nexus-admin/</url>
        </pluginRepository>
    </pluginRepositories>

4、创建测试类

由此可见,可在项目中自动引用本地仓库中的 jar 包。

创建自定义仓库组并在项目中引用已上传至本地仓库中的 jar 包操作完毕!

至此,Nexus 部分私服配置操作完毕!后期或有补充!

希望能够对您有所帮助!

参考地址:

https://blog.csdn.net/u012637358/article/details/93832491

猜你喜欢

转载自blog.csdn.net/llwy1428/article/details/105084057
今日推荐