-
Notifications
You must be signed in to change notification settings - Fork 14
/
RemotePublishing.kt
141 lines (123 loc) · 4.47 KB
/
RemotePublishing.kt
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
140
141
/*
* Copyright (c) 2019 Toast, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.google.protobuf.gradle.GenerateProtoTask
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinJs
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.the
import org.gradle.kotlin.dsl.withType
import org.gradle.plugins.signing.Sign
import org.gradle.plugins.signing.SigningExtension
private object Pgp {
val key by lazy {
System.getenv("PGP_KEY")?.replace('$', '\n')
}
val password by lazy {
System.getenv("PGP_PASSWORD")
}
}
object ProtoktProjectInfo {
const val NAME = "Protokt"
const val URL = "https://github.com/open-toast/protokt"
const val DESCRIPTION = "Protobuf compiler and runtime for Kotlin"
}
fun Project.isRelease() = !version.toString().endsWith("-SNAPSHOT")
fun Project.enablePublishing(defaultJars: Boolean = true) {
apply(plugin = "com.vanniktech.maven.publish.base")
configure<PublishingExtension> {
repositories {
maven {
name = "integration"
setUrl("${project.rootProject.layout.buildDirectory.get()}/repos/integration")
}
}
}
configure<MavenPublishBaseExtension> {
pom {
name.set(ProtoktProjectInfo.NAME)
description.set(ProtoktProjectInfo.DESCRIPTION)
url.set(ProtoktProjectInfo.URL)
scm { url.set(ProtoktProjectInfo.URL) }
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http:https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("Toast")
name.set("Toast Open Source")
email.set("[email protected]")
}
}
}
if (defaultJars) {
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
configure(KotlinMultiplatform(JavadocJar.Empty()))
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
configure(KotlinJvm(JavadocJar.Empty(), true))
}
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
configure(KotlinJs(JavadocJar.Empty()))
}
}
afterEvaluate {
tasks.withType<Jar> {
dependsOn(tasks.withType<GenerateProtoTask>())
}
}
}
if (isRelease()) {
configure<MavenPublishBaseExtension> {
publishToMavenCentral(SonatypeHost.DEFAULT, true)
}
apply(plugin = "signing")
configure<SigningExtension> {
useInMemoryPgpKeys(Pgp.key, Pgp.password)
afterEvaluate {
the<PublishingExtension>()
.publications
.withType<MavenPublication>()
.forEach(::sign)
}
}
afterEvaluate {
tasks.withType<PublishToMavenRepository> {
dependsOn(tasks.withType<Sign>())
}
}
}
tasks.register("publishToIntegrationRepository") {
group = "publishing"
val publishingExtension = project.the<PublishingExtension>()
dependsOn(
tasks.withType<PublishToMavenRepository>().matching {
it.repository == publishingExtension.repositories.getByName("integration")
}
)
}
}