Gradle 设置 Nexus 用户名密码

直接在Gradle中明文写上用户名、密码不仅会涉及安全性问题,更为Git的管理带来诸多不便。

有一个变通的方法如下:

新建一个Gradle属性文件~/.gradle/gradle.properties,可以将用户名、密码以变量的形式存入文本:

1
2
NEXUS_USER=yourname
NEXUS_PASSWORD=yourpassword

接着在Gradle文件中即可引用上述变量:

1
2
3
4
5
6
7
8
9
10
11
12
allprojects {
repositories {
jcenter()
maven {
url "http://ip:port/repository/maven-releases/"
credentials {
username = "${NEXUS_USER}"
password = "${NEXUS_PASSWORD}"
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
uploadArchives {
configuration = configurations.archives
repositories {
mavenDeployer {
repository(url: "http://ip:port/repository/maven-releases/") {
authentication(userName: NEXUS_USER, password: NEXUS_PASSWORD)
}
pom.project {
version '1.0.0'
artifactId 'pay'
groupId 'me.yezhou'
packaging 'aar'
description 'pay library'
}
}
}
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2021 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :