-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
215 lines (194 loc) · 6.14 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION as KOTLIN_VERSION
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
`java-gradle-plugin`
signing
`maven-publish`
alias(libs.plugins.githubrelease)
alias(libs.plugins.gradlePluginPublish)
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.semver)
alias(libs.plugins.versions)
alias(libs.plugins.nexus.publish)
}
semver {
tagPrefix("v")
initialVersion("0.0.1")
findProperty("semver.overrideVersion")?.toString()?.let { overrideVersion(it) }
findProperty("semver.modifier")?.toString()?.let { versionModifier(buildVersionModifier(it)) } // this is only used for non user defined strategies, ie predefined Flow or Flat
}
val invalidQualifiers = setOf("alpha", "beta", "rc", "nightly")
fun hasInvalidQualifier(candidate: ModuleComponentIdentifier): Boolean {
return invalidQualifiers.any { candidate.version.contains(it) }
}
configurations.all {
resolutionStrategy {
eachDependency {
if (requested.group == "org.jetbrains.kotlin") {
useVersion(libs.versions.kotlin.get())
}
}
componentSelection {
all {
if (!(candidate.group.startsWith("com.figure") || (candidate.group.startsWith("io.provenance"))) && hasInvalidQualifier(candidate))
reject("invalid qualifier versions for $candidate")
}
}
}
}
/*
* Project information
*/
group = "io.github.nefilim.gradle"
description = "Modified Git Flow based semver plugin"
version = semver.version
inner class ProjectInfo {
val longName = "Gradle Semver Plugin"
val pluginImplementationClass = "$group.semver.SemVerPlugin"
val tags = listOf("semver", "gitflow")
val website = "https://github.com/nefilim/gradle-semver-plugin"
val vcsURL = "https://github.com/nefilim/gradle-semver-plugin.git"
}
val info = ProjectInfo()
repositories {
mavenCentral()
}
dependencies {
api(gradleApi())
api(gradleKotlinDsl())
api(kotlin("stdlib-jdk8"))
implementation(libs.arrow.core)
implementation(libs.eclipse.jgit.eclipseJgit)
runtimeOnly(libs.eclipse.jgit.ssh.apache)
api(libs.swiftzer.semver)
testImplementation(gradleTestKit())
testImplementation(libs.bundles.kotest)
}
// Enforce Kotlin version coherence
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.kotlin" && requested.name.startsWith("kotlin")) {
useVersion(KOTLIN_VERSION)
because("All Kotlin modules should use the same version, and compiler uses $KOTLIN_VERSION")
}
}
}
kotlin {
target {
compilations.all {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf("-version", "-Xjsr305=strict", "-Xopt-in=kotlin.RequiresOptIn")
jvmTarget = "11"
languageVersion = "1.5"
apiVersion = "1.5"
verbose = true
}
}
}
}
java {
withSourcesJar()
withJavadocJar()
}
tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = sourceCompatibility
}
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
}
}
// can only be applied to root project
nexusPublishing {
repositories {
sonatype {
username.set(System.getenv("OSS_USER"))
password.set(System.getenv("OSS_TOKEN"))
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
signing {
val skipSigning = findProperty("skipSigning")?.let { (it as String).toBoolean() } ?: false
if (!skipSigning) {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
} else {
logger.warn("skipping signing")
}
}
pluginBundle {
website = info.website
vcsUrl = info.vcsURL
tags = info.tags
}
gradlePlugin {
plugins {
create(project.name) {
id = "$group.${project.name}"
displayName = info.longName
description = project.description
implementationClass = info.pluginImplementationClass
}
}
}
fun MavenPublication.addSonaTypeRequirements() {
this.pom {
name.set(project.name)
description.set("Git Flow Semver Gradle Plugin")
url.set(info.website)
licenses {
license {
name.set("GPL-3.0-only")
url.set("https://opensource.org/licenses/GPL-3.0")
}
}
developers {
developer {
id.set("nefilim")
name.set("nefilim")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:${info.vcsURL}")
url.set(info.website)
}
}
}
afterEvaluate {
publishing {
publications {
names.filter { it.contains("plugin", ignoreCase = true) }.map {
logger.lifecycle("decorating publication [$it]")
findByName(it)?.let { it as MavenPublication }?.apply { addSonaTypeRequirements() } ?: logger.error("failed to find publication [$it]")
}
}
}
val skipSigning = findProperty("skipSigning")?.let { (it as String).toBoolean() } ?: false
if (!skipSigning)
signing.sign(publishing.publications)
}
val githubTokenValue = findProperty("githubToken")?.toString() ?: System.getenv("GITHUB_TOKEN")
githubRelease {
token(githubTokenValue)
owner("nefilim")
repo("gradle-semver-plugin")
tagName(semver.versionTagName)
targetCommitish("main")
body(changelog())
draft(false)
prerelease(false)
overwrite(false)
dryRun(false)
apiEndpoint("https://api.github.com")
client
}