-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
203 lines (174 loc) · 6.48 KB
/
build.gradle.kts
File metadata and controls
203 lines (174 loc) · 6.48 KB
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
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.jvm.tasks.Jar
plugins {
`maven-publish`
signing
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
id("net.researchgate.release") version "3.1.0" apply false
}
fun localRepositoryDirectories() = sequenceOf(
providers.gradleProperty("localRepositoryPaths").orNull,
providers.environmentVariable("LOCAL_REPOSITORY_PATHS").orNull
)
.filterNotNull()
.flatMap { it.split(',').asSequence() }
.map(String::trim)
.filter(String::isNotEmpty)
.map(::file)
.distinctBy { it.absoluteFile.normalize() }
.toList()
val gitTrackedPaths = providers.exec {
workingDir(rootDir)
commandLine("git", "ls-files", "-z")
}.standardOutput.asText.map { output ->
output
.split('\u0000')
.filter(String::isNotBlank)
.toSet()
}
val sourcesJar by tasks.registering(Jar::class) {
group = "build"
description = "Packages all Git-tracked files from the repository as a sources JAR."
archiveClassifier.set("sources")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
from(rootDir) {
includeEmptyDirs = false
exclude { element ->
!element.isDirectory && element.relativePath.pathString !in gitTrackedPaths.get()
}
}
}
allprojects {
group = "org.openprojectx.ai.plugin"
version = rootProject.version
repositories {
localRepositoryDirectories().forEach { repoDir ->
maven(url = repoDir.toURI())
}
mavenCentral()
}
apply(plugin = "kotlin-jvm")
}
publishing {
publications {
create<MavenPublication>("rootModule") {
artifactId = "${rootProject.name}-root"
from(components["java"])
artifact(sourcesJar)
pom {
name.set("AI Test Plugin Root Module")
description.set("Root Maven publication for the AI Test Plugin build")
url.set("https://github.com/OpenProjectX/ai-test-plugin")
licenses {
license {
name.set("Apache License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("OpenProjectX")
name.set("OpenProjectX")
email.set("admin@openprojectx.org")
}
}
scm {
connection.set("scm:git:https://github.com/OpenProjectX/ai-test-plugin.git")
developerConnection.set("scm:git:ssh://git@github.com:OpenProjectX/ai-test-plugin.git")
url.set("https://github.com/OpenProjectX/ai-test-plugin.git")
}
}
}
}
}
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
// username.set(providers.gradleProperty("sonatypeUsername"))
// password.set(providers.gradleProperty("sonatypePassword"))
username.set(System.getenv("OSSRH_USERNAME"))
password.set(System.getenv("OSSRH_PASSWORD"))
}
}
}
signing {
val isCi: Boolean by gradle.extra
if (isCi) {
val keyFile = System.getenv("SIGNING_KEY_FILE")
if (keyFile != null) {
val keyText = file(keyFile).readText()
val keyPass = System.getenv("SIGNING_KEY_PASSWORD")
useInMemoryPgpKeys(keyText, keyPass)
sign(publishing.publications["rootModule"])
}
}
}
// Drive release through an explicit nested build.
//
// The researchgate release plugin is not configuration-cache compatible on Gradle 9.x,
// and its default outer "release" task spawns another GradleBuild that can recurse into
// a second nested build. The failure shows up as:
// :ai-test-plugin-release:ai-test-plugin-release:beforeReleaseBuild not found
//
// To keep the plugin contained, the outer build defines its own GradleBuild task and only
// applies the plugin inside the nested "<root>-release" build.
val releaseLifecycleTasks = listOf(
":createScmAdapter",
":initScmAdapter",
":checkCommitNeeded",
":checkUpdateNeeded",
":checkoutMergeToReleaseBranch",
":unSnapshotVersion",
":confirmReleaseVersion",
":checkSnapshotDependencies",
":beforeReleaseBuild",
":plugin-idea:publishPlugin",
":afterReleaseBuild",
":preTagCommit",
":createReleaseTag",
":checkoutMergeFromReleaseBranch",
":updateVersion",
":commitNewVersion"
)
val isNestedReleaseBuild = gradle.parent != null &&
providers.gradleProperty("release.releasing").orNull == "true"
val outerProjectProperties = gradle.startParameter.projectProperties
val outerSystemProperties = gradle.startParameter.systemPropertiesArgs
if (isNestedReleaseBuild) {
apply(plugin = "net.researchgate.release")
configure<net.researchgate.release.ReleaseExtension> {
// The nested build already runs the release lifecycle. Clearing buildTasks prevents
// runBuildTasks from spawning a second nested build.
buildTasks.set(emptyList())
tagTemplate.set("\${version}")
git {
requireBranch.set("main")
}
}
tasks.configureEach {
notCompatibleWithConfigurationCache("net.researchgate.release nested build is not configuration cache compatible")
}
} else {
tasks.register<GradleBuild>("release") {
group = "Release"
description = "Verify project, release, and update version to next."
buildName = "${project.name}-release"
dir = rootDir
setTasks(releaseLifecycleTasks)
startParameter = gradle.startParameter.newBuild().apply {
setTaskNames(releaseLifecycleTasks)
projectProperties = outerProjectProperties +
mapOf(
"org.gradle.configuration-cache" to "false",
"release.releasing" to "true"
)
systemPropertiesArgs = outerSystemProperties + ("org.gradle.configuration-cache" to "false")
}
notCompatibleWithConfigurationCache("release uses a nested Gradle build with configuration cache disabled")
}
}