blob: 7af7b69f9151de5e1d2b65b2950f79429f3ee2e1 (
plain)
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
|
package buildsrc.conventions
import buildsrc.settings.MavenPublishingSettings
plugins {
`maven-publish`
signing
}
val mavenPublishing =
extensions.create<MavenPublishingSettings>(MavenPublishingSettings.EXTENSION_NAME, project)
//region POM convention
publishing {
publications.withType<MavenPublication>().configureEach {
pom {
name.convention("Dokkatoo")
description.convention("Dokkatoo is a Gradle plugin that generates documentation for your Kotlin projects")
url.convention("https://github.com/adamko-dev/dokkatoo")
scm {
connection.convention("scm:git:https://github.com/adamko-dev/dokkatoo")
developerConnection.convention("scm:git:https://github.com/adamko-dev/dokkatoo")
url.convention("https://github.com/adamko-dev/dokkatoo")
}
licenses {
license {
name.convention("Apache-2.0")
url.convention("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
email.set("adam@adamko.dev")
}
}
}
}
}
//endregion
//region GitHub branch publishing
publishing {
repositories {
maven(mavenPublishing.githubPublishDir) {
name = "GitHubPublish"
}
}
}
//endregion
//region Maven Central publishing/signing
publishing {
repositories {
val mavenCentralUsername = mavenPublishing.mavenCentralUsername.orNull
val mavenCentralPassword = mavenPublishing.mavenCentralPassword.orNull
if (!mavenCentralUsername.isNullOrBlank() && !mavenCentralPassword.isNullOrBlank()) {
maven(mavenPublishing.sonatypeReleaseUrl) {
name = "SonatypeRelease"
credentials {
username = mavenCentralUsername
password = mavenCentralPassword
}
}
}
}
// com.gradle.plugin-publish automatically adds a Javadoc jar
}
signing {
logger.info("maven-publishing.gradle.kts enabled signing for ${project.path}")
val keyId = mavenPublishing.signingKeyId.orNull
val key = mavenPublishing.signingKey.orNull
val password = mavenPublishing.signingPassword.orNull
if (!keyId.isNullOrBlank() && !key.isNullOrBlank() && !password.isNullOrBlank()) {
useInMemoryPgpKeys(keyId, key, password)
}
setRequired({
gradle.taskGraph.allTasks.filterIsInstance<PublishToMavenRepository>().any {
it.repository.name == "SonatypeRelease"
}
})
}
//afterEvaluate {
// com.gradle.plugin-publish automatically signs tasks in a weird way, that stops this from working:
// signing {
// sign(publishing.publications)
// }
//}
//endregion
//region Fix Gradle warning about signing tasks using publishing task outputs without explicit dependencies
// https://youtrack.jetbrains.com/issue/KT-46466 https://github.com/gradle/gradle/issues/26091
tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTasks = tasks.withType<Sign>()
mustRunAfter(signingTasks)
}
//endregion
//region publishing logging
tasks.withType<AbstractPublishToMaven>().configureEach {
val publicationGAV = provider { publication?.run { "$group:$artifactId:$version" } }
doLast("log publication GAV") {
if (publicationGAV.isPresent) {
logger.lifecycle("[task: ${path}] ${publicationGAV.get()}")
}
}
}
//endregion
//region IJ workarounds
// manually define the Kotlin DSL accessors because IntelliJ _still_ doesn't load them properly
fun Project.publishing(configure: PublishingExtension.() -> Unit): Unit =
extensions.configure(configure)
val Project.publishing: PublishingExtension
get() = extensions.getByType()
fun Project.signing(configure: SigningExtension.() -> Unit): Unit =
extensions.configure(configure)
val Project.signing: SigningExtension
get() = extensions.getByType()
//endregion
|