SpringBoot 学习

CentOS7 maven私库搭建及使用简例

2019-10-30  本文已影响0人  国服最坑开发

0x01来由

随着开发业务的不断开展, 会出现相同的业务功能代码在不同的项目中贴来贴去.
本着不想偷懒的程序员决逼不是好橱子的精神, 决定优化一下开发体验.
由于是公司业务相关代码, 故只能选择在内网环境搭建服务.

0x02 Nexus服务器软件搭建

useradd nexus
passwd nexus
su - nexus

vim /home/nexus/nexus-3.19.1-01/etc/nexus-default.properties
# 这个端口改为希望使用的服务端口
application-port=10000
/home/nexus/nexus-3.19.1-01/bin/nexus start

启动完成后通过 IP:PORT 进行访问

0x03 关于Admin密码

第一次登录时, 会提示使用 admin登录,
密码内容保存在服务器文件中 :/home/nexus/sonatype-work/nexus3/admin.password
修改成新密码后, 这个文件会消失, 注意保存密码

登录

0x04 创建一个私库(hosted)存储节点(repo)

进入管理 repo 创建新repo 选择类型 maven2 (hosted)

这一步需要注意的点, 如下图所示: 节点名称, 还有允许重发布


设置内容 完成

点击COPY, 就可以拿到私库的访问地址


仓库的URL

0x05 提交一个版本到私库

使用IDEA 创建一个空的 maven 项目

留意一下 groupId相关信息, Version中使用纯数字.

设置信息
<?xml version="1.0" encoding="UTF-8"?>
<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.gorey</groupId>
    <artifactId>SayHello</artifactId>
    <version>0.0.1</version>

    <distributionManagement>
        <repository>
            <id>com-repo</id>
            <url>http://HOST:10000/repository/com-repo/</url>
        </repository>
    </distributionManagement>

</project>
    <server>
      <id>com-repo</id>
      <username>admin</username>
      <password>PASSWD</password>
    </server>

留意, id需和 pom.xml里的一致.

完成后, 可以在服务端查看


server

0x06 使用私库的版本

<?xml version="1.0" encoding="UTF-8"?>
<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.demo</groupId>
    <artifactId>RepoDemo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>com-repo</id>
            <url>http://HOST:10000/repository/com-repo/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.gorey</groupId>
            <artifactId>SayHello</artifactId>
            <version>0.0.1</version>
        </dependency>
    </dependencies>
</project>
public class Main {
    public static void main(String[] args) {
        System.out.println(SayHello.say("国服最坑开发"));
    }
}

效果

0x07 完

谢谢观赏, 感觉这个流程真的好简单, 接下来的工作, 就是去提取代码入库 - -!!!

上一篇 下一篇

猜你喜欢

热点阅读