Based Nexus 3.x build Gradle Maven local private warehouse

I believe engaged in the development of Java or Android friends for Gradle Maven repository and not feel strange, thanks to powerful open source strength, build local PW a lot easier. This paper briefly record to build on Sonatype Nexus management tools, easy to remember.

Based on the windows environment Nexus (Nexus Repository Manager) 3.15.2 version of the build, the download link or visit the official website to download.

First, build a Nexus

Download Unzip the package to the appropriate directory.

This F:\Programs\nexus-3.15.2-01article: .
Again: As developers should avoid directory contains Chinese characters or spaces

To 管理员身份运行"command prompt" windows command window

Command into the nexus of the implementation of the directory "bin":

  1. Cut into the nexus where the first letter of the file, the paper tray for the F
    C:\WINDOWS\system32>F:
  1. Then enter the "bin" directory
    F:\>cd Programs\nexus-3.15.2-01\bin

Command to install the nexus Service

    F:\Programs\nexus-3.15.2-01\bin>nexus.exe/install
  • Tips for success:
    Installed service 'nexus'.
  • If you have already installed the good tips:
    Service is already stopped.
    Installed service 'nexus'.

It does not matter, just stop and automatically install the service cover.

  • If you are prompted:
    Could not open SCManager.

Big reason that you do not run as an administrator Command Prompt window or not to get administrator privileges.

Open service

    F:\Programs\nexus-3.15.2-01\bin>nexus.exe/start
  • Tips for success:
    Starting service 'nexus'.

It indicates the service is turned on, pay attention: On success does not give tips, and after waiting a few seconds can enjoy the results of your installation.

Close Service

    F:\Programs\nexus-3.15.2-01\bin>nexus.exe/stop

Tips for success:

    Stopping service 'nexus'.
    Service stopped

Second, create a Maven repository

Automatically creates a service enabling users after nexus: admin, password: admin123 administrator account. Service access port: 8081

  1. Open the web browser to access the service nexus end, enter the address as: "ip address: 8081", a local direct inputlocalhost:8081
  2. Click on the top right of the web page "Sign in" button to log in, enter the above account to sign in.
  3. After logging in, press the arrow button click order

To choose to create a repository interface

Various types of warehouse for us to choose, including the type of Maven, Nexus offers to create three types of Maven repository, where we choose relatively simple "maven2 (hosted)".

填写仓库名,简单起见其它项保持默认即可,创建仓库

创建完成后,会自动返回上一页到已创建的仓库列表界面,最下方会列出刚刚创建的“Test”仓库一栏,然后点击此栏上的“copy”按钮即可复制该仓库的链接url,本文为:http://localhost:8081/repository/Test/

三、代码库上传

配置上传gradle脚本

在依赖Module项目下的build.gradle文件上编辑以下脚本(以CySwitch为例):

    apply plugin: 'maven'
    
    uploadArchives {
        repositories {
            mavenDeployer {
                //仓库地址
                repository(url: "http://localhost:8081/repository/Test/") {
                    // 验证账号,即nexus服务管理账号
                    authentication(userName: "admin", password: "admin123")
                }
                pom.groupId = 'cn.icheny.view' // 组织id,一般习惯用包名标识
                pom.artifactId = 'CySwitch' // 项目名
                pom.version = '1.0.2' //发布版本号
    
                // 下面内容可选,需要描述许可证的情况下
                pom.project {
                    licenses {
                        license {
                            name 'The Apache Software License, Version 2.0'
                            url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }
                }
            }
        }
    }

执行脚本任务

配置完毕后,Snyc一下,在Gradle的界面模块会出现“upload–>uploadArchives”任务,双击即可执行编译上传任务:

获取依赖库远程依赖脚本

  1. 任务执行完毕后,回到浏览器,按下图操作:

  1. 双击“Test”仓库这一栏,就可以看到上传的依赖库了。这时候点击依赖库的版本号,右边就会出现当前依赖库的管理功能模块。

眼尖的童鞋应该很快就能看到右下方熟悉的信息,远程依赖脚本:

    implementation 'cn.icheny.view:CySwitch:1.0.2'

脚本上方有个“copy”按钮,可直接复制脚本。

四、远程依赖

本来写到上方就算结束了,但是为了防止童鞋们在使用远程依赖遇到问题,这里还是说一下吧。

配置远程仓库地址

在Project下的build.gradle中添加仓库地址:

    allprojects {
        repositories {
            ......
            // 添加Nexus maven仓库地址
            maven { url "http://localhost:8081/repository/Test/" }
        }
    }

配置依赖脚本

这一步大家都知道,在需要依赖的Module下的build.gradle中添加依赖脚本:

    dependencies {
        ......
        implementation 'cn.icheny.view:CySwitch:1.0.2'
    }

至此,本文全部结束,希望能给同行朋友们带来一些帮助。

Guess you like

Origin blog.csdn.net/ausboyue/article/details/87908581