-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.gradle.kts
192 lines (155 loc) · 5.13 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
import java.util.concurrent.Callable
plugins {
`java-library`
signing
`maven-publish`
id("uk.jamierocks.propatcher") version "1.3.2"
id("org.cadixdev.licenser") version "0.5.0"
}
val artifactId = name.toLowerCase()
base.archivesBaseName = artifactId
java {
sourceCompatibility = JavaVersion.VERSION_1_8
}
configurations {
register("jdt") {
isTransitive = false
}
}
repositories {
mavenCentral()
}
val jdt = "org.eclipse.jdt:org.eclipse.jdt.core:3.25.0"
dependencies {
api(jdt)
// TODO: Split in separate modules
api("org.cadixdev:at:0.1.0-rc1")
api("org.cadixdev:lorenz:0.5.7")
"jdt"("$jdt: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("${project.group}.$artifactId.jdt.".replace('.', '/'))
}
// Patched ImportRewrite from JDT
patches {
patches = file("patches")
root = file("build/jdt/original")
target = file("build/jdt/patched")
}
val jdtSrcDir = file("jdt")
val extract = task<Copy>("extractJdt") {
dependsOn(configurations["jdt"])
from(Callable { zipTree(configurations["jdt"].singleFile) })
destinationDir = patches.root
include("org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java")
include("org/eclipse/jdt/internal/core/dom/rewrite/imports/*.java")
}
tasks["applyPatches"].inputs.files(extract)
val renames = listOf(
"org.eclipse.jdt.core.dom.rewrite" to "$group.$artifactId.jdt.rewrite.imports",
"org.eclipse.jdt.internal.core.dom.rewrite.imports" to "$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 "${project.group}.$artifactId"))
}
tasks.withType<Test> {
useJUnitPlatform()
}
val sourceJar = task<Jar>("sourceJar") {
classifier = "sources"
from(sourceSets["main"].allSource)
}
val javadocJar = task<Jar>("javadocJar") {
classifier = "javadoc"
from(tasks["javadoc"])
}
artifacts {
add("archives", sourceJar)
add("archives", javadocJar)
}
license {
header = file("HEADER")
exclude("$group.$artifactId.jdt.".replace('.', '/'))
}
val isSnapshot = version.toString().endsWith("-SNAPSHOT")
publishing {
publications {
register<MavenPublication>("mavenJava") {
from(components["java"])
artifactId = base.archivesBaseName
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("jmansfield@cadixdev.org")
url("https://www.jamiemansfield.me/")
timezone("Europe/London")
}
}
}
}
}
repositories {
val sonatypeUsername: String? by project
val sonatypePassword: String? by project
if (sonatypeUsername != null && sonatypePassword != null) {
val url = if (isSnapshot) "https://oss.sonatype.org/content/repositories/snapshots/"
else "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
maven(url) {
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
}
}
}
signing {
sign(publishing.publications["mavenJava"])
}
tasks.withType<Sign> {
onlyIf { !isSnapshot }
}
operator fun Property<String>.invoke(v: String) = set(v)