搭建本地maven仓库实战

时间:2022-02-27 15:24:36

搭建本地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'
}

参考文献