搭建本地maven仓库实战

Posted ihrthk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建本地maven仓库实战相关的知识,希望对你有一定的参考价值。

搭建本地maven仓库实战

1 搭建本地maven

1.1 下载nexus(http://www.sonatype.org/nexus/archived/)

1.2 解压放到之后放到/Library/nexus-2.14.2-01

1.3 配置修改

在Nexus的安装目录找到/bin/nexus,修改NEXUS_HOMERUN_AS_USER两个参数如下。

NEXUS_HOME="/Library/nexus-2.14.2-01"

# If specified, the Wrapper will be run as the specified user.

# IMPORTANT - Make sure that the user has the required privileges to write into the Nexus installation directory.

# NOTE - This will set the user which is used to run the Wrapper as well as
#  the JVM and is not useful in situations where a privileged resource or
#  port needs to be allocated prior to the user being changed.
RUN_AS_USER=root

# Application
APP_NAME="nexus"
APP_LONG_NAME="Nexus OSS"

2 启动服务

2.1 sudo su (输入密码以后即可切换到root用户)

2.2 /Library/nexus-2.14.2-01/bin/nexus start

2.3 使用浏览器,打开http://localhost:8081/nexus/

3 上传构件到Maven仓库

apply plugin: 'maven'

uploadArchives 
    repositories 
        mavenDeployer 
            repository(url: "http://localhost:8081/nexus/content/repositories/android/") 
                authentication(userName: "admin", password: "admin123")
            
            pom.version = "1.0"
            pom.artifactId = "deskcore"
            pom.groupId = "com.le"
        
    

4 使用构件

在项目的根目录gradle.build文件,添加本地的meaven仓库

buildscript 
    repositories 
        jcenter()
        maven 
            credentials 
                username 'admin'
                password 'admin123'
            
            url 'http://localhost:8081/nexus/content/repositories/android/'
        
    
    dependencies 
        classpath 'com.android.tools.build:gradle:2.2.3'
    


allprojects 
    repositories 
        jcenter()
    

在具体的module的gradle.build文件,添加对应的依赖

dependencies 
    compile 'com.le:ucenter-core:1.0'

参考文献

以上是关于搭建本地maven仓库实战的主要内容,如果未能解决你的问题,请参考以下文章

Maven实战与原理分析:手把手带你搭建maven私有仓库

centos7案例实战——Nexus3伺服仓库服务器搭建

centos7案例实战——Nexus3伺服仓库服务器搭建

[Maven实战]仓库(本地仓库,远程仓库,镜像)

nexus 搭建maven本地仓库

《Maven实战》笔记-3-Maven仓库