Skip to content

Commit 20bf6f4

Browse files
build: better configuration avoidance
1 parent 76170e5 commit 20bf6f4

File tree

4 files changed

+53
-45
lines changed

4 files changed

+53
-45
lines changed

modules/api-client-jdk11/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ kotlin {
4545
}
4646

4747
tasks {
48-
withType<JavaCompile> {
48+
withType<JavaCompile>().configureEach {
4949
options.release.set(11)
5050
}
5151

52-
withType<KotlinCompile> {
52+
withType<KotlinCompile>().configureEach {
5353
kotlinOptions {
5454
languageVersion = "1.7"
5555
apiVersion = "1.7"

modules/api-client-ktor/build.gradle.kts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ java {
4040
kotlin {
4141
explicitApi()
4242

43-
targets.all {
44-
compilations.all {
43+
targets.configureEach {
44+
compilations.configureEach {
4545
kotlinOptions {
4646
languageVersion = "1.7"
4747
apiVersion = "1.7"
@@ -54,7 +54,7 @@ kotlin {
5454
nodejs()
5555
}
5656
jvm {
57-
compilations.all {
57+
compilations.configureEach {
5858
kotlinOptions {
5959
jvmTarget = "11"
6060
}
@@ -81,26 +81,30 @@ kotlin {
8181
}
8282
}
8383

84-
getByName("jvmMain").dependencies {
85-
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
84+
named("jvmMain") {
85+
dependencies {
86+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
87+
}
8688
}
8789

88-
getByName("jvmTest").dependencies {
89-
implementation("org.jetbrains.kotlin:kotlin-test-junit5")
90-
implementation(libs.junit.jupiter.api)
91-
implementation(libs.ktor.client.apache)
90+
named("jvmTest") {
91+
dependencies {
92+
implementation("org.jetbrains.kotlin:kotlin-test-junit5")
93+
implementation(libs.junit.jupiter.api)
94+
implementation(libs.ktor.client.apache)
9295

93-
runtimeOnly(libs.junit.jupiter.engine)
96+
runtimeOnly(libs.junit.jupiter.engine)
97+
}
9498
}
9599
}
96100
}
97101

98102
tasks {
99-
withType<JavaCompile> {
103+
withType<JavaCompile>().configureEach {
100104
options.release.set(11)
101105
}
102106

103-
getByName<org.gradle.jvm.tasks.Jar>("jvmJar") {
107+
named<org.gradle.jvm.tasks.Jar>("jvmJar") {
104108
manifest {
105109
attributes(mapOf(
106110
"Name" to project.name,
@@ -120,7 +124,7 @@ val emptyJavadocJar by tasks.registering(Jar::class) {
120124
}
121125

122126
publishing {
123-
publications.withType<MavenPublication>().all {
127+
publications.withType<MavenPublication>().configureEach {
124128
if (name == "js") artifact(emptyJar)
125129
artifact(emptyJavadocJar)
126130

modules/api-client/build.gradle.kts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,8 @@ java {
4242
kotlin {
4343
explicitApi()
4444

45-
targets.all {
46-
compilations.all {
47-
compileKotlinTask.apply {
48-
dependsOn(project(":").tasks["generate"])
49-
}
50-
45+
targets.configureEach {
46+
compilations.configureEach {
5147
kotlinOptions {
5248
languageVersion = "1.7"
5349
apiVersion = "1.7"
@@ -74,7 +70,7 @@ kotlin {
7470
}
7571
}
7672
jvm {
77-
compilations.all {
73+
compilations.configureEach {
7874
kotlinOptions {
7975
jvmTarget = "11"
8076
}
@@ -110,19 +106,19 @@ kotlin {
110106
dependsOn(nonJvmMain)
111107
}
112108

113-
getByName("jsTest") {
109+
named("jsTest") {
114110
dependencies {
115111
api(libs.kotlin.test.js)
116112
}
117113
}
118114

119-
getByName("jvmMain") {
115+
named("jvmMain") {
120116
dependencies {
121117
api(libs.kotlinx.coroutines.jdk8)
122118
}
123119
}
124120

125-
getByName("jvmTest") {
121+
named("jvmTest") {
126122
dependencies {
127123
api(libs.kotlin.test.junit5)
128124
}
@@ -131,15 +127,15 @@ kotlin {
131127
}
132128

133129
tasks {
134-
withType<JavaCompile> {
130+
withType<JavaCompile>().configureEach {
135131
options.release.set(11)
136132
}
137133

138-
withType<KotlinCompile> {
134+
withType<KotlinCompile>().configureEach {
139135
dependsOn(project(":").tasks["generate"])
140136
}
141137

142-
getByName<org.gradle.jvm.tasks.Jar>("jvmJar") {
138+
named<org.gradle.jvm.tasks.Jar>("jvmJar") {
143139
manifest {
144140
attributes(mapOf(
145141
"Name" to project.name,
@@ -156,11 +152,15 @@ tasks {
156152
dependsOn(project(":").tasks["generate"])
157153
}
158154

159-
getByName("jsSourcesJar") {
155+
named("jsSourcesJar") {
156+
dependsOn(project(":").tasks["generate"])
157+
}
158+
159+
named("jvmSourcesJar") {
160160
dependsOn(project(":").tasks["generate"])
161161
}
162162

163-
withType<DokkaTask> {
163+
withType<DokkaTask>().configureEach {
164164
dependsOn(project(":").tasks["generate"])
165165
}
166166
}
@@ -171,7 +171,7 @@ val emptyJavadocJar by tasks.registering(Jar::class) {
171171
}
172172

173173
publishing {
174-
publications.withType<MavenPublication>().all {
174+
publications.withType<MavenPublication>().configureEach {
175175
if (name == "js") artifact(emptyJar)
176176
artifact(emptyJavadocJar)
177177

modules/api-types/build.gradle.kts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,8 @@ java {
4242
kotlin {
4343
explicitApi()
4444

45-
targets.all {
46-
compilations.all {
47-
compileKotlinTask.apply {
48-
dependsOn(project(":").tasks["generate"])
49-
}
50-
45+
targets.configureEach {
46+
compilations.configureEach {
5147
kotlinOptions {
5248
languageVersion = "1.7"
5349
apiVersion = "1.7"
@@ -60,7 +56,7 @@ kotlin {
6056
nodejs()
6157
}
6258
jvm {
63-
compilations.all {
59+
compilations.configureEach {
6460
kotlinOptions {
6561
jvmTarget = "11"
6662
}
@@ -90,13 +86,13 @@ kotlin {
9086
}
9187
}
9288

93-
getByName("jsTest") {
89+
named("jsTest") {
9490
dependencies {
9591
api(libs.kotlin.test.js)
9692
}
9793
}
9894

99-
getByName("jvmTest") {
95+
named("jvmTest") {
10096
dependencies {
10197
api(libs.kotlin.test.junit5)
10298
}
@@ -105,11 +101,15 @@ kotlin {
105101
}
106102

107103
tasks {
108-
withType<JavaCompile> {
104+
withType<JavaCompile>().configureEach {
109105
options.release.set(11)
110106
}
111107

112-
getByName<org.gradle.jvm.tasks.Jar>("jvmJar") {
108+
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
109+
dependsOn(project(":").tasks["generate"])
110+
}
111+
112+
named<org.gradle.jvm.tasks.Jar>("jvmJar") {
113113
manifest {
114114
attributes(mapOf(
115115
"Name" to project.name,
@@ -126,11 +126,15 @@ tasks {
126126
dependsOn(project(":").tasks["generate"])
127127
}
128128

129-
getByName("jsSourcesJar") {
129+
named("jsSourcesJar") {
130+
dependsOn(project(":").tasks["generate"])
131+
}
132+
133+
named("jvmSourcesJar") {
130134
dependsOn(project(":").tasks["generate"])
131135
}
132136

133-
withType<DokkaTask> {
137+
withType<DokkaTask>().configureEach {
134138
dependsOn(project(":").tasks["generate"])
135139
}
136140
}
@@ -141,7 +145,7 @@ val emptyJavadocJar by tasks.registering(Jar::class) {
141145
}
142146

143147
publishing {
144-
publications.withType<MavenPublication>().all {
148+
publications.withType<MavenPublication>().configureEach {
145149
if (name == "js") artifact(emptyJar)
146150
artifact(emptyJavadocJar)
147151

0 commit comments

Comments
 (0)