-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaven.gradle
102 lines (90 loc) · 3.15 KB
/
maven.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Properties loadProperties(File file) {
if (file.exists()) {
Properties props = new Properties()
props.load(new FileInputStream(file))
return props
} else {
return null
}
}
def addMaven(String repoName, File propFile) {
def prop = loadProperties(propFile)
if (prop == null) {
println "${repoName} 配置文件不存在:{$propFile.absolutePath}"
return
}
def mavenPath = prop.getProperty("MAVEN_PATH")
def mavenPathSnapshot = prop.getProperty("MAVEN_PATH")
def mavenUser = prop.getProperty("MAVEN_USER")
def mavenPwd = prop.getProperty("MAVEN_PWD")
addMaven(repoName, mavenPath, mavenPathSnapshot, mavenUser, mavenPwd)
}
def addEnvRepo(
String name = "DEFAULT_MAVEN",
String mavenPathKey = "MAVEN_PATH",
String mavenPathSnapshotKey = "MAVEN_PATH_SNAPSHOT",
String mavenUserKey = "MAVEN_USER",
String mavenPwdKey = "MAVEN_PWD"
) {
def mavenPath = System.getenv(mavenPathKey)
def mavenPathSnapshot = System.getenv(mavenPathSnapshotKey)
def mavenUser = System.getenv(mavenUserKey)
def mavenPwd = System.getenv(mavenPwdKey)
if (mavenPath != null && !mavenPath.isBlank()) {
addEnvRepo(name,
mavenPath,
mavenPathSnapshot,
mavenUser,
mavenPwd)
}
}
def addMaven(String repoName, String mavenPath, String mavenPathSnapshot, String mavenUser, String mavenPwd) {
rootProject.buildscript.repositories {
maven {
url mavenPath
if (mavenUser != null || !mavenUser.isBlank()) {
credentials {
username mavenUser
password mavenPwd
}
}
}
}
rootProject.subprojects {
repositories {
maven {
url mavenPath
if (mavenUser != null || !mavenUser.isBlank()) {
credentials {
username mavenUser
password mavenPwd
}
}
}
}
if (plugins.hasPlugin('com.android.application')) {
return
}
plugins.withId("com.vanniktech.maven.publish") {
publishing {
repositories {
maven {
name = repoName
def releasesRepoUrl = mavenPath
def snapshotsRepoUrl = mavenPathSnapshot == null || mavenPathSnapshot.isBlank() ? mavenPath : mavenPathSnapshot
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
if (mavenUser != null || !mavenUser.isBlank()) {
credentials {
username mavenUser
password mavenPwd
}
}
}
}
}
}
}
}
addMaven("AliDev", file(System.getProperty("user.home") + "/.m2/alidev.properties"))
//System.getProperty("user.home")+"/.m2/alidev.properties"
//rootProject.file("alidev.properties")