-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
139 lines (116 loc) · 4.12 KB
/
build.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
buildscript {
repositories {
mavenCentral()
jcenter()
mavenLocal()
maven {
url "https://dl.bintray.com/ppanda-beta/maven"
}
}
}
plugins {
id 'org.ajoberstar.grgit' version '1.7.2' apply false
id 'org.ajoberstar.release-opinion' version '1.7.2' apply false
id 'com.github.johnrengelman.shadow' version '6.0.0' apply false
}
allprojects {
repositories {
mavenCentral()
jcenter()
mavenLocal()
maven {
url "https://dl.bintray.com/ppanda-beta/maven"
}
}
}
subprojects {
apply plugin: 'maven-publish'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'org.ajoberstar.grgit'
apply plugin: 'org.ajoberstar.release-opinion'
apply plugin: 'com.github.johnrengelman.shadow'
afterEvaluate {
shadowJar {
zip64 = true
relocate('com.google', 'ppanda.shaded.com.google')
}
}
}
ext {
bintrayUserName = findProperty("bintrayUserName")
bintrayApiToken = findProperty("bintrayApiToken")
signingKey = findProperty("signingKey")
signingPassword = findProperty("signingPassword")
}
void setupPublishing(prj, artifactName, pomName, pomDescription) {
prj.publishing {
publications {
"$prj.name"(MavenPublication) {
from prj.components.java
artifactId artifactName
pom {
name = pomName
description = pomDescription
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'ppanda-beta'
name = 'Palash Das'
email = '[email protected]'
}
}
}
}
}
repositories {
maven {
name "jCenterOf" + prj.name
credentials {
username = bintrayUserName
password = bintrayApiToken
}
url = "https://api.bintray.com/maven/${bintrayUserName}/maven/${artifactName}/;publish=1"
}
}
}
def removeCurrentVersionTask = prj.task("removeCurrentVersionIfExists", {
doFirst {
deleteArtifactVersion(prj.version, artifactName, false)
}
})
def removePoisonousMavenVersionTask = prj.task("removePoisonousMavenMetadataBasedFakeVersion", {
doLast {
deleteArtifactVersion(artifactName, artifactName)
}
})
def tasks = prj.getTasks()
def publishToJCenterTask = tasks.find { task ->
task.name.contains("ToJCenterOf${prj.name}Repository")
}
publishToJCenterTask.dependsOn(removeCurrentVersionTask)
publishToJCenterTask.finalizedBy(removePoisonousMavenVersionTask)
prj.signing {
useInMemoryPgpKeys(signingKey, signingPassword)
sign prj.publishing.publications[prj.name]
}
}
private void deleteArtifactVersion(versionId, artifactName, stopOnFail = true) {
def artifactLocation = "https://api.bintray.com/packages/${bintrayUserName}/maven/${artifactName}/versions/${versionId}"
def basicAuthHeader = "Basic " + Base64.getEncoder().encodeToString((bintrayUserName + ":" + bintrayApiToken).getBytes())
def deleteConnection = new URL(artifactLocation).openConnection();
deleteConnection.setRequestMethod("DELETE")
deleteConnection.setRequestProperty("Authorization", basicAuthHeader)
deleteConnection.setDoOutput(true)
deleteConnection.getOutputStream().flush()
if (deleteConnection.getResponseCode().equals(200)) {
println("Successfully deleted artifact " + deleteConnection.getInputStream().getText())
} else if (stopOnFail) {
throw new StopActionException("Failed to delete artifact " + deleteConnection.getInputStream().getText())
}
}