-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
131 lines (113 loc) · 3.94 KB
/
build.gradle.kts
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
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") apply false
`maven-publish`
signing
}
subprojects {
version = extra["project.version"]!!.toString()
group = extra["project.group"]!!.toString()
tasks.withType<JavaCompile> {
sourceCompatibility = "1.8"
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
jvmTarget = "1.8"
}
}
apply(plugin = "org.gradle.maven-publish")
apply(plugin = "org.gradle.signing")
apply(plugin = "java")
tasks.withType<Jar> {
archiveClassifier.set("")
}
extensions.getByType<JavaPluginExtension>().run {
withSourcesJar()
withJavadocJar()
}
val projectUrl = extra["project.url"]!!.toString()
val projectDescription = extra["project.description"]!!.toString()
val projectLicense = extra["project.license"]!!.toString()
val projectLicenseUrl = extra["project.license.url"]!!.toString()
val projectDeveloperId = extra["project.developer.id"]!!.toString()
val projectDeveloperName = extra["project.developer.name"]!!.toString()
val projectDeveloperEmail = extra["project.developer.email"]!!.toString()
val projectUrlScm = extra["project.url.scm"]!!.toString()
fun setupPom(mavenPom: MavenPom) {
with(mavenPom) {
name.set(project.rootProject.name)
url.set(projectUrl)
description.set(projectDescription)
licenses {
license {
name.set(projectLicense)
url.set(projectLicenseUrl)
}
}
developers {
developer {
id.set(projectDeveloperId)
name.set(projectDeveloperName)
email.set(projectDeveloperEmail)
}
scm {
url.set(projectUrlScm)
}
}
}
}
publishing {
publications {
create<MavenPublication>("mavenCentral") {
this.groupId = extra["project.group"]!!.toString()
this.version = extra["project.version"]!!.toString()
this.artifactId = project.name.lowercase()
from(components["java"])
setupPom(pom)
signing {
sign(this@publications)
}
}
}
repositories {
maven {
name = "sonatype"
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = System.getenv("OSSRH_USERNAME")
password = System.getenv("OSSRH_PASSWORD")
}
}
}
}
signing {
setRequired {
!project.version.toString()
.contains("-SNAPSHOT") && gradle.taskGraph.allTasks.any { it is PublishToMavenRepository }
}
if (!extra.has("signing.keyId")) {
extra["signing.keyId"] = System.getenv("SIGNING_KEY_ID")
}
if (!extra.has("signing.password")) {
extra["signing.password"] = System.getenv("SIGNING_PASSPHRASE")
}
if (!extra.has("signing.secretKeyRingFile")) {
extra["signing.secretKeyRingFile"] =
if (System.getenv("SIGNING_SECRET_KEY_RING_FILE_ABSOLUTE") != null) {
System.getenv("SIGNING_SECRET_KEY_RING_FILE_ABSOLUTE")
} else {
System.getenv("HOME") + "/" + System.getenv("SIGNING_SECRET_KEY_RING_FILE")
}
}
sign(extensions.getByType(PublishingExtension::class).publications)
}
tasks.withType(GenerateMavenPom::class.java) {
doFirst {
setupPom(pom)
}
}
tasks.withType(PublishToMavenRepository::class.java) {
dependsOn(tasks.withType<Sign>())
}
}