forked from CadixDev/Mercury
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
247 lines (199 loc) · 7.43 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import java.util.concurrent.Callable
plugins {
`java-library`
`maven-publish`
id("uk.jamierocks.propatcher") version "2.0.1"
id("org.cadixdev.licenser") version "0.6.1"
id("com.github.johnrengelman.shadow") version "7.1.2"
}
val og_group: String by project
val artifactId = name.toLowerCase()
base.archivesName.set(artifactId)
java {
sourceCompatibility = JavaVersion.VERSION_1_8
}
val build = "release #${System.getenv("GITHUB_RUN_NUMBER") ?: "custom"}"
version = project.findProperty("base_version") as String + "." + (System.getenv("GITHUB_RUN_NUMBER") ?: "9999")
logger.lifecycle(":building mercury v${version}")
fun Short.absoluteValue(): Short =
if (this < 0) (-this).toShort() else this
configurations {
register("jdtSources") {
isTransitive = false
}
register("jdt")
}
configurations["api"].extendsFrom(configurations["jdt"])
repositories {
mavenCentral()
}
// Update with: ./gradlew dependencies --write-locks
dependencyLocking {
lockAllConfigurations()
lockMode.set(LockMode.STRICT)
}
val jdtVersion = "org.eclipse.jdt:org.eclipse.jdt.core:3.35.0"
dependencies {
// JDT pulls all of these deps in, however they do not specify the exact version to use so they can get updated without us knowing.
// Depend specifically on these versions to prevent them from being updated under our feet.
// The POM is also patched later on to as this strict versioning does not make it through.
"jdt" (jdtVersion)
// TODO: Split in separate modules
api("org.cadixdev:at:0.1.0-rc1")
api("org.cadixdev:lorenz:0.5.7")
"jdtSources"("$jdtVersion:sources")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.cadixdev:lorenz-io-jam:0.5.7")
}
tasks.withType<Javadoc> {
exclude("$og_group.$artifactId.jdt.".replace('.', '/'))
}
// Patched ImportRewrite from JDT
patches {
patches = file("patches")
rootDir = file("build/jdt/original")
target = file("build/jdt/patched")
}
val jdtSrcDir = file("jdt")
val extract = task<Copy>("extractJdt") {
dependsOn(configurations["jdtSources"])
from(Callable { zipTree(configurations["jdtSources"].singleFile) })
destinationDir = patches.rootDir
include("org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java")
include("org/eclipse/jdt/internal/core/dom/rewrite/imports/*.java")
}
tasks["applyPatches"].inputs.files(extract)
tasks["resetSources"].inputs.files(extract)
tasks["resetSources"].dependsOn(tasks.register("ensureTargetDirectory") {
doLast {
patches.target.mkdirs()
}
})
val renames = listOf(
"org.eclipse.jdt.core.dom.rewrite" to "$og_group.$artifactId.jdt.rewrite.imports",
"org.eclipse.jdt.internal.core.dom.rewrite.imports" to "$og_group.$artifactId.jdt.internal.rewrite.imports"
)
fun createRenameTask(prefix: String, inputDir: File, outputDir: File, renames: List<Pair<String, String>>): Task
= task<Copy>("${prefix}renameJdt") {
destinationDir = file(outputDir)
renames.forEach { (old, new) ->
from("$inputDir/${old.replace('.', '/')}") {
into("${new.replace('.', '/')}/")
}
}
filter { renames.fold(it) { s, (from, to) -> s.replace(from, to) } }
}
val renameTask = createRenameTask("", patches.target, jdtSrcDir, renames)
renameTask.inputs.files(tasks["applyPatches"])
tasks["makePatches"].inputs.files(createRenameTask("un", jdtSrcDir, patches.target, renames.map { (a,b) -> b to a }))
sourceSets["main"].java.srcDirs(renameTask)
tasks.jar.configure {
manifest.attributes(mapOf("Automatic-Module-Name" to "$og_group.$artifactId"))
archiveClassifier.set("raw")
enabled = false
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<JavaCompile> {
options.release.set(17)
}
tasks.build.configure { dependsOn(tasks.shadowJar) }
tasks.withType<GenerateModuleMetadata>().configureEach {
enabled = false
}
tasks.shadowJar {
archiveClassifier.set("")
configurations = listOf(project.configurations["jdt"])
relocate("org.apache", "org.cadixdev.mercury.shadow.org.apache")
relocate("org.eclipse", "org.cadixdev.mercury.shadow.org.eclipse")
relocate("org.osgi", "org.cadixdev.mercury.shadow.org.osgi")
}
val sourceJar = task<Jar>("sourceJar") {
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
val javadocJar = task<Jar>("javadocJar") {
archiveClassifier.set("javadoc")
from(tasks["javadoc"])
}
artifacts {
add("archives", sourceJar)
add("archives", javadocJar)
add("archives", tasks.shadowJar)
}
license {
setHeader(file("HEADER"))
exclude("org.cadixdev.$artifactId.jdt.".replace('.', '/'))
}
val isSnapshot = true
listOf(configurations.apiElements, configurations.runtimeElements).forEach { config ->
(components["java"] as AdhocComponentWithVariants).withVariantsFromConfiguration(config.get()) {
configurationVariant.artifacts.removeIf { artifact ->
artifact.file == tasks.jar.get().archiveFile.get().asFile
}
}
}
publishing {
publications {
register<MavenPublication>("mavenJava") {
from(components["java"])
artifactId = base.archivesName.get()
artifact(sourceJar)
artifact(javadocJar)
pom {
val name: String by project
val description: String by project
val url: String by project
name(name)
description(description)
url(url)
scm {
url(url)
connection("scm:git:$url.git")
developerConnection.set(connection)
}
issueManagement {
system("GitHub Issues")
url("$url/issues")
}
licenses {
license {
name("Eclipse Public License, Version 2.0")
url("https://www.eclipse.org/legal/epl-2.0/")
distribution("repo")
}
}
developers {
developer {
id("jamierocks")
name("Jamie Mansfield")
email("[email protected]")
url("https://www.jamiemansfield.me/")
timezone("Europe/London")
}
}
withXml {
// I pray that im being stupid that this isn't what you have to put up with when using kotlin
(((asNode().get("dependencies") as groovy.util.NodeList).first() as groovy.util.Node).value() as groovy.util.NodeList)
.removeIf { node ->
val group = ((((node as groovy.util.Node).get("groupId") as groovy.util.NodeList).first() as groovy.util.Node).value() as groovy.util.NodeList).first() as String
group.startsWith("org.eclipse.")
}
}
}
}
}
repositories {
if (System.getenv("MAVEN_PASS") != null) {
maven("https://deploy.shedaniel.me/") {
credentials {
username = "shedaniel"
password = System.getenv("MAVEN_PASS")
}
}
}
}
}
operator fun Property<String>.invoke(v: String) = set(v)