-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.gradle.kts
157 lines (141 loc) · 4.41 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`java-gradle-plugin`
alias(libs.plugins.dokka)
alias(libs.plugins.gitSemVer)
alias(libs.plugins.gradlePluginPublish)
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.qa)
alias(libs.plugins.publishOnCentral)
alias(libs.plugins.multiJvmTesting)
alias(libs.plugins.taskTree)
}
gitSemVer {
buildMetadataSeparator.set("-")
}
group = "org.danilopianini"
class ProjectInfo {
val longName = "Gradle Publish On Maven Central Plugin"
val projectDetails = "A Plugin for easily publishing artifacts on Maven Central"
val website = "https://github.com/DanySK/$name"
val vcsUrl = "$website.git"
val scm = "scm:git:$website.git"
val pluginImplementationClass = "$group.gradle.mavencentral.PublishOnCentral"
val tags = listOf("template", "kickstart", "example")
}
val info = ProjectInfo()
repositories {
mavenCentral()
gradlePluginPortal()
}
multiJvm {
maximumSupportedJvmVersion.set(latestJavaSupportedByGradle)
}
dependencies {
api(kotlin("stdlib"))
api(gradleApi())
api(gradleKotlinDsl())
api(libs.kotlin.gradlePlugin)
api(libs.dokka.gradlePlugin)
api(libs.nexus.publish)
api(libs.maven.central.api)
implementation(libs.kotlinx.coroutines)
implementation(libs.fuel)
testImplementation(libs.testkit)
testImplementation(libs.bundles.kotlin.testing)
}
/*
* The following lines are a workaround for
* https://github.com/gradle/gradle/issues/16603.
* The issue is related to the Gradle Daemon getting terminated by the Gradle Testkit,
* and the JaCoCo agent not waiting for it.
*/
inline fun <reified T : Task> Project.disableTrackState() {
tasks.withType<T>().configureEach {
doNotTrackState("Otherwise JaCoCo does not work correctly")
}
}
disableTrackState<Test>()
disableTrackState<JacocoReport>()
tasks.withType<KotlinCompile> {
compilerOptions {
allWarningsAsErrors = true
}
}
tasks.withType<Test> {
useJUnitPlatform()
testLogging {
showStandardStreams = true
showCauses = true
showStackTraces = true
events(
*org.gradle.api.tasks.testing.logging.TestLogEvent
.values(),
)
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
gradlePlugin {
plugins {
website.set(info.website)
vcsUrl.set(info.vcsUrl)
create("PublishOnCentralPlugin") {
id = "$group.${project.name}"
displayName = info.longName
description = project.description
implementationClass = info.pluginImplementationClass
tags.set(info.tags)
description = info.projectDetails
}
}
}
publishOnCentral {
projectDescription.set(info.projectDetails)
projectLongName.set(info.longName)
projectUrl.set(info.website)
scmConnection.set(info.scm)
repository("https://maven.pkg.github.com/DanySK/$name".lowercase()) {
user.set("danysk")
password.set(System.getenv("GITHUB_TOKEN"))
}
publishing {
publications {
withType<MavenPublication> {
pom {
developers {
developer {
name.set("Danilo Pianini")
email.set("[email protected]")
url.set("http://www.danilopianini.org/")
}
}
}
}
}
}
}
if (System.getenv("CI") == true.toString()) {
signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
}
}
val registerCredentials =
tasks.register("registerGradlePluginPortalCredentials") {
doLast {
listOf("gradle.publish.key", "gradle.publish.secret").forEach {
if (!(project.hasProperty(it) or System.getenv().containsKey(it))) {
val bashName = it.uppercase().replace(".", "_")
System.getProperties().setProperty(
it,
System.getenv(bashName)
?: error("Property $it is unset and environment variable $bashName unavailable"),
)
}
}
}
}
tasks.publishPlugins {
dependsOn(registerCredentials)
}