-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
229 lines (175 loc) · 7.15 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
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.LinkMapping
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.w3c.dom.Element
import org.w3c.dom.Node
import org.w3c.dom.NodeList
plugins {
kotlin("jvm") version "1.3.10"
id("org.jetbrains.dokka") version "0.9.17"
id("io.codearte.nexus-staging") version "0.11.0"
`maven-publish`
signing
}
val kotlinVersion by extra { "1.3.10" } // sync with above
val repoAddress = "https://github.com/oowekyala/kt-tree-matchers"
group = "com.github.oowekyala.treeutils"
version = "2.1.0"
repositories {
jcenter()
}
dependencies {
constraints {
testImplementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
}
}
subprojects {
val sub = this@subprojects
sub.group = rootProject.group
sub.version = rootProject.version
repositories {
jcenter()
}
apply<KotlinPluginWrapper>()
apply<DokkaPlugin>()
apply<MavenPublishPlugin>()
apply<SigningPlugin>()
dependencies {
compileOnly(kotlin("stdlib-jdk7"))
// test use case
testCompile("net.sourceforge.pmd:pmd-java:6.6.0")
testImplementation(kotlin("test"))
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.1.11")
testRuntime("org.slf4j:slf4j-api:1.7.25")
testRuntime("org.slf4j:slf4j-log4j12:1.7.25")
}
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
test {
useJUnitPlatform { }
}
dokka {
outputDirectory = "$buildDir/javadoc"
outputFormat = "html"
includes += "../dokka.md"
linkMapping(delegateClosureOf<LinkMapping> {
dir = "src/main/kotlin"
url = "$repoAddress/blob/master/$dir"
suffix = "#L"
})
}
val dokkaJar by creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
classifier = "javadoc"
from(dokka)
}
val sourcesJar by creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles sources JAR"
classifier = "sources"
from(sourceSets["main"].allSource)
}
publishing {
publications {
create<MavenPublication>("default") {
groupId = sub.group.toString()
artifactId = sub.name
version = sub.version.toString()
from(sub.components["java"])
artifact(dokkaJar)
artifact(sourcesJar)
pom {
operator fun <T> Property<T>.invoke(value: T): Unit = set(value)
val mvnName = sub.name
.replace('-', ' ')
.split(" ")
.map { it.capitalize() }
.joinToString(separator = " ") { it }
.let { "$it for Kotlin" }
name(mvnName)
packaging = "jar"
description(
if (sub.name == "tree-matchers")
"A testing DSL to specify the structure of a tree in a concise and readable way."
else
"A set of pretty printers for trees, any trees."
)
url(repoAddress)
inceptionYear("2018")
scm {
url(repoAddress)
connection("scm:$repoAddress.git")
developerConnection("scm:$repoAddress.git")
}
licenses {
license {
name("The Unlicense")
url("http://unlicense.org/UNLICENSE")
distribution("repo")
}
}
developers {
developer {
id("oowekyala")
name("Clément Fournier")
email("clement.fournier76@gmail.com")
}
}
withXml {
fun NodeList.asList(): List<Node> = (0..length).map { item(it) }
val root = this.asElement().ownerDocument
fun elt(name: String, contents: (Element) -> Unit = {}) =
root.createElement(name).also {
contents(it)
} as Element
fun Node.plus(name: String, text: String? = null): Element =
appendChild(elt(name) {
if (text != null)
it.appendChild(root.createTextNode(text))
}) as Element
val dependencies =
root.getElementsByTagName("dependencies").asList().firstOrNull()
?: root.documentElement.plus("dependencies")
sub.configurations.compileOnly.allDependencies.forEach { dep ->
val node = elt("dependency") {
it.plus("groupId", dep.group ?: "")
it.plus("artifactId", dep.name)
dep.version?.let { v -> it.plus("version", v) }
it.plus("scope", "provided")
}
dependencies.appendChild(node)
}
}
}
}
}
repositories {
maven {
val myUrl =
if (version.toString().endsWith("-SNAPSHOT"))
"https://oss.sonatype.org/content/repositories/snapshots"
else
"https://oss.sonatype.org/service/local/staging/deploy/maven2"
url = uri(myUrl)
credentials {
username = property("nexusUsername").toString()
password = property("nexusPassword").toString()
}
}
}
}
signing {
sign(publishing.publications["default"])
}
}
}