Skip to content

Commit a6bce83

Browse files
committed
build > improve and simplify code
1 parent 84f78c9 commit a6bce83

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

build.gradle.kts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ dependencies {
8787

8888
/* ******************** optional dependencies ******************** */
8989

90-
listOf("websocket", "proxy", "epoll").forEach {
91-
java.registerFeature(it) {
90+
for (feature in listOf("websocket", "proxy", "epoll")) {
91+
java.registerFeature(feature) {
9292
usingSourceSet(sourceSets["main"])
9393
}
9494
}
@@ -170,12 +170,10 @@ tasks.shadowJar {
170170
archiveAppendix.set("shaded")
171171
archiveClassifier.set("")
172172

173-
configurations = listOf(project.run {
174-
configurations.create("shaded") {
175-
extendsFrom(configurations["runtimeClasspath"])
176-
configurations["apiElements"].allDependencies.forEach {
177-
exclude(it.group, it.name)
178-
}
173+
configurations = listOf(project.configurations.create("shaded") {
174+
extendsFrom(project.configurations["runtimeClasspath"])
175+
for (apiDependency in project.configurations["apiElements"].allDependencies) {
176+
exclude(apiDependency.group, apiDependency.name)
179177
}
180178
})
181179

@@ -195,7 +193,7 @@ tasks.shadowJar {
195193

196194
/* ******************** publishing ******************** */
197195

198-
apply("${rootDir}/gradle/publishing.gradle.kts")
196+
apply("$rootDir/gradle/publishing.gradle.kts")
199197

200198
allprojects {
201199
plugins.withId("java-library") {
@@ -226,11 +224,11 @@ publishing.publications.register<MavenPublication>("shaded") {
226224
artifact(tasks["sourcesJar"])
227225
pom.withXml {
228226
asNode().appendNode("dependencies").apply {
229-
configurations["apiElements"].allDependencies.forEach {
227+
for (apiDependency in configurations["apiElements"].allDependencies) {
230228
appendNode("dependency").apply {
231-
appendNode("groupId", it.group)
232-
appendNode("artifactId", it.name)
233-
appendNode("version", it.version)
229+
appendNode("groupId", apiDependency.group)
230+
appendNode("artifactId", apiDependency.name)
231+
appendNode("version", apiDependency.version)
234232
appendNode("scope", "compile")
235233
}
236234
}
@@ -240,18 +238,14 @@ publishing.publications.register<MavenPublication>("shaded") {
240238

241239
allprojects {
242240
plugins.withId("maven-publish") {
243-
afterEvaluate {
244-
publishing.publications.withType<MavenPublication>().configureEach {
245-
pom.withXml {
246-
(asNode()["dependencies"] as groovy.util.NodeList).forEach { dependencies ->
247-
(dependencies as groovy.util.Node).children().forEach { dependency ->
248-
val dep = dependency as groovy.util.Node
249-
val optional = dep["optional"] as groovy.util.NodeList
250-
val scope = dep["scope"] as groovy.util.NodeList
251-
if (!optional.isEmpty() && (optional[0] as groovy.util.Node).text() == "true") {
252-
(scope[0] as groovy.util.Node).setValue("runtime")
253-
}
254-
}
241+
publishing.publications.withType<MavenPublication>().configureEach {
242+
pom.withXml {
243+
val dependencies = (asNode()["dependencies"] as groovy.util.NodeList)[0] as groovy.util.Node
244+
for (dependency in dependencies.children()) {
245+
dependency as groovy.util.Node
246+
val optional = dependency["optional"] as groovy.util.NodeList
247+
if (!optional.isEmpty() && (optional[0] as groovy.util.Node).text() == "true") {
248+
((dependency["scope"] as groovy.util.NodeList)[0] as groovy.util.Node).setValue("runtime")
255249
}
256250
}
257251
}

0 commit comments

Comments
 (0)