11import com.diffplug.gradle.spotless.SpotlessExtension
2+ import org.gradle.kotlin.dsl.sourceSets
23import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
4+ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
5+ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
6+ import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
37import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
48
59plugins {
@@ -9,44 +13,58 @@ plugins {
913
1014kotlin {
1115 applyDefaultHierarchyTemplate()
16+ registerJavaTest(" javaTest" ) {
17+ java.srcDir(" src/jvmJavaTest/proto-java" )
18+ java.srcDir(" src/jvmJavaTest/proto-kotlin" )
19+ }
20+
21+ registerJavaTest(" javaNoOptionsTest" ) {
22+ java.srcDir(" src/jvmJavaNoOptionsTest/proto-java" )
23+ }
24+
25+ registerJavaTest(" javaCompactTest" ) {
26+ java.srcDir(" src/jvmJavaCompactTest/proto-java" )
27+ }
28+
29+ registerJavaTest(" javaPrunedTest" ) {
30+ java.srcDir(" src/jvmJavaPrunedTest/proto-java" )
31+ }
32+
33+ registerJavaTest(" javaAndroidTest" ) {
34+ java.srcDir(" src/jvmJavaAndroidTest/proto-java" )
35+ }
36+
37+ registerJavaTest(" javaAndroidCompactTest" ) {
38+ java.srcDir(" src/jvmJavaAndroidCompactTest/proto-java" )
39+ }
40+
41+ registerJavaTest(" jsonJavaTest" ) {
42+ java.srcDir(" src/jvmJsonTest/kotlin" )
43+ java.srcDir(" src/jvmJsonJavaTest/proto-java" )
44+ }
45+
46+ registerJavaTest(" jsonKotlinTest" ) {
47+ java.srcDir(" src/jvmJsonTest/kotlin" )
48+ java.srcDir(" src/jvmJsonKotlinTest/proto-kotlin" )
49+ }
50+
1251 jvm {
13- val kotlinInteropTest by compilations.creating {
14- defaultSourceSet {
15- kotlin.srcDir(" src/jvmKotlinInteropTest/proto-kotlin" )
16- dependencies {
17- implementation(projects.wireRuntime)
18- implementation(libs.kotlin.test.junit)
19- implementation(libs.assertk)
20- implementation(libs.kotlin.reflect)
21- }
22- }
23- val jvmKotlinInteropTest by tasks.registering(Test ::class ) {
24- classpath = compileDependencyFiles + runtimeDependencyFiles + output.allOutputs
25- testClassesDirs = output.classesDirs
26- }
27- val jvmTest by tasks.getting {
28- dependsOn(jvmKotlinInteropTest)
29- dependencies {
30- implementation(projects.wireGrpcClient)
31- }
52+ registerKotlinTest(" kotlinInteropTest" ) {
53+ kotlin.srcDir(" src/jvmKotlinInteropTest/proto-kotlin" )
54+ dependencies {
55+ implementation(projects.wireRuntime)
56+ implementation(libs.kotlin.test.junit)
57+ implementation(libs.assertk)
58+ implementation(libs.kotlin.reflect)
3259 }
3360 }
34- val kotlinAndroidTest by compilations.creating {
35- defaultSourceSet {
61+ registerKotlinTest(" kotlinAndroidTest" ) {
3662 kotlin.srcDir(" src/jvmKotlinAndroidTest/proto-kotlin" )
3763 dependencies {
3864 implementation(projects.wireRuntime)
3965 compileOnly(libs.android)
4066 implementation(libs.kotlin.test.junit)
4167 implementation(libs.assertk)
42- }
43- }
44- val jvmKotlinAndroidTest by tasks.registering(Test ::class ) {
45- classpath = compileDependencyFiles + runtimeDependencyFiles + output.allOutputs
46- testClassesDirs = output.classesDirs
47- }
48- val jvmTest by tasks.getting {
49- dependsOn(jvmKotlinAndroidTest)
5068 }
5169 }
5270 val kotlinProtoReader32Test by compilations.creating {
@@ -132,127 +150,90 @@ kotlin {
132150
133151val jvmTest by tasks.getting
134152
135- for (target in kotlin.targets.matching { it.platformType.name == " jvm" }) {
136- target.project.sourceSets {
137- val test by getting {
138- java.srcDir(" src/jvmTest/proto-java" )
139- }
140-
141- val javaTest by creating {
142- java.srcDir(" src/jvmJavaTest/proto-java" )
143- java.srcDir(" src/jvmJavaTest/proto-kotlin" )
144- }
145- val jvmJavaTest by tasks.registering(Test ::class ) {
146- classpath = javaTest.runtimeClasspath
147- testClassesDirs = javaTest.output.classesDirs
148- }
149- jvmTest.dependsOn(jvmJavaTest)
150-
151- val javaNoOptionsTest by creating {
152- java.srcDir(" src/jvmJavaNoOptionsTest/proto-java" )
153- }
154- val jvmJavaNoOptionsTest by tasks.registering(Test ::class ) {
155- classpath = javaNoOptionsTest.runtimeClasspath
156- testClassesDirs = javaNoOptionsTest.output.classesDirs
157- }
158- jvmTest.dependsOn(jvmJavaNoOptionsTest)
159-
160- val javaCompactTest by creating {
161- java.srcDir(" src/jvmJavaCompactTest/proto-java" )
162- }
163- val jvmJavaCompactTest by tasks.registering(Test ::class ) {
164- classpath = javaCompactTest.runtimeClasspath
165- testClassesDirs = javaCompactTest.output.classesDirs
153+ fun KotlinJvmTarget.registerKotlinTest (
154+ name : String ,
155+ configureSourceSet : KotlinSourceSet .() -> kotlin.Unit ,
156+ ) {
157+ val kotlinInteropTest = compilations.create(name) {
158+ defaultSourceSet {
159+ configureSourceSet()
166160 }
167- jvmTest.dependsOn(jvmJavaCompactTest)
168-
169- val javaPrunedTest by creating {
170- java.srcDir(" src/jvmJavaPrunedTest/proto-java" )
171- }
172- val jvmJavaPrunedTest by tasks.registering(Test ::class ) {
173- classpath = javaPrunedTest.runtimeClasspath
174- testClassesDirs = javaPrunedTest.output.classesDirs
175- }
176- jvmTest.dependsOn(jvmJavaPrunedTest)
177-
178- val javaAndroidTest by creating {
179- java.srcDir(" src/jvmJavaAndroidTest/proto-java" )
161+ val jvmKotlinInteropTest by tasks.registering(Test ::class ) {
162+ classpath = compileDependencyFiles + runtimeDependencyFiles + output.allOutputs
163+ testClassesDirs = output.classesDirs
180164 }
181- val jvmJavaAndroidTest by tasks.registering(Test ::class ) {
182- classpath = javaAndroidTest.runtimeClasspath
183- testClassesDirs = javaAndroidTest.output.classesDirs
184- }
185- jvmTest.dependsOn(jvmJavaAndroidTest)
186-
187- val javaAndroidCompactTest by creating {
188- java.srcDir(" src/jvmJavaAndroidCompactTest/proto-java" )
189- }
190- val jvmJavaAndroidCompactTest by tasks.registering(Test ::class ) {
191- classpath = javaAndroidCompactTest.runtimeClasspath
192- testClassesDirs = javaAndroidCompactTest.output.classesDirs
165+ val jvmTest by tasks.getting {
166+ dependsOn(jvmKotlinInteropTest)
167+ dependencies {
168+ implementation(projects.wireGrpcClient)
169+ }
193170 }
194- jvmTest.dependsOn(jvmJavaAndroidCompactTest)
171+ }
172+ }
195173
196- val jsonJavaTest by creating {
197- java.srcDir(" src/jvmJsonTest/kotlin" )
198- java.srcDir(" src/jvmJsonJavaTest/proto-java" )
174+ fun KotlinMultiplatformExtension.registerJavaTest (
175+ name : String , // Like jvmJavaTest
176+ configureSourceSet : SourceSet .() -> Unit ,
177+ ) {
178+ sourceSets {
179+ jvm { }
180+ }
181+ project.sourceSets {
182+ val sourceSet: SourceSet = create(name) {
183+ configureSourceSet()
199184 }
200- val jvmJsonJavaTest by tasks.registering( Test ::class ) {
201- classpath = jsonJavaTest .runtimeClasspath
202- testClassesDirs = jsonJavaTest .output.classesDirs
185+ val taskProvider = tasks.register(name, Test ::class ) {
186+ classpath = sourceSet .runtimeClasspath
187+ testClassesDirs = sourceSet .output.classesDirs
203188 }
204- jvmTest.dependsOn(jvmJsonJavaTest)
189+ jvmTest.dependsOn(taskProvider)
190+ }
191+ }
205192
206- val jsonKotlinTest by creating {
207- java.srcDir(" src/jvmJsonTest/kotlin" )
208- java.srcDir(" src/jvmJsonKotlinTest/proto-kotlin" )
209- }
210- val jvmJsonKotlinTest by tasks.registering(Test ::class ) {
211- classpath = jsonKotlinTest.runtimeClasspath
212- testClassesDirs = jsonKotlinTest.output.classesDirs
213- }
214- jvmTest.dependsOn(jvmJsonKotlinTest)
193+ sourceSets {
194+ val jvmTest by getting {
195+ java.srcDir(" src/jvmTest/proto-java" )
196+ }
197+ }
215198
216- dependencies {
217- add(" javaTestImplementation" , projects.wireRuntime)
218- add(" javaNoOptionsTestImplementation" , projects.wireRuntime)
219- add(" javaCompactTestImplementation" , projects.wireRuntime)
220- add(" javaPrunedTestImplementation" , projects.wireRuntime)
221- add(" javaAndroidTestImplementation" , projects.wireRuntime)
222- add(" javaAndroidCompactTestImplementation" , projects.wireRuntime)
223- add(" jsonJavaTestImplementation" , projects.wireRuntime)
224- add(" jsonKotlinTestImplementation" , projects.wireRuntime)
199+ dependencies {
200+ add(" javaTestImplementation" , projects.wireRuntime)
201+ add(" javaNoOptionsTestImplementation" , projects.wireRuntime)
202+ add(" javaCompactTestImplementation" , projects.wireRuntime)
203+ add(" javaPrunedTestImplementation" , projects.wireRuntime)
204+ add(" javaAndroidTestImplementation" , projects.wireRuntime)
205+ // add("javaAndroidCompactTestImplementation", projects.wireRuntime)
206+ add(" jsonJavaTestImplementation" , projects.wireRuntime)
207+ add(" jsonKotlinTestImplementation" , projects.wireRuntime)
225208
226- add(" javaAndroidTestCompileOnly" , libs.android)
227- add(" javaAndroidCompactTestCompileOnly" , libs.android)
228- add(" javaAndroidTestCompileOnly" , libs.androidx.annotations)
229- add(" javaAndroidCompactTestCompileOnly" , libs.androidx.annotations)
209+ add(" javaAndroidTestCompileOnly" , libs.android)
210+ // add("javaAndroidCompactTestCompileOnly", libs.android)
211+ add(" javaAndroidTestCompileOnly" , libs.androidx.annotations)
212+ // add("javaAndroidCompactTestCompileOnly", libs.androidx.annotations)
230213
231- add(" javaTestImplementation" , libs.kotlin.test.junit)
232- add(" javaTestImplementation" , libs.assertk)
233- add(" javaTestImplementation" , libs.jimfs)
234- add(" javaTestImplementation" , libs.truth)
235- add(" jsonJavaTestImplementation" , projects.wireMoshiAdapter)
236- add(" jsonJavaTestImplementation" , projects.wireGsonSupport)
237- add(" jsonJavaTestImplementation" , projects.wireTestUtils)
238- add(" jsonJavaTestImplementation" , libs.kotlin.test.junit)
239- add(" jsonJavaTestImplementation" , libs.assertk)
240- add(" jsonJavaTestImplementation" , libs.jimfs)
241- add(" jsonJavaTestImplementation" , libs.truth)
242- add(" jsonKotlinTestImplementation" , projects.wireMoshiAdapter)
243- add(" jsonKotlinTestImplementation" , projects.wireGsonSupport)
244- add(" jsonKotlinTestImplementation" , projects.wireTestUtils)
245- add(" jsonKotlinTestImplementation" , libs.kotlin.test.junit)
246- add(" jsonKotlinTestImplementation" , libs.assertk)
247- add(" jsonKotlinTestImplementation" , libs.jimfs)
248- add(" jsonKotlinTestImplementation" , libs.truth)
214+ add(" javaTestImplementation" , libs.kotlin.test.junit)
215+ add(" javaTestImplementation" , libs.assertk)
216+ add(" javaTestImplementation" , libs.jimfs)
217+ add(" javaTestImplementation" , libs.truth)
218+ add(" jsonJavaTestImplementation" , projects.wireMoshiAdapter)
219+ add(" jsonJavaTestImplementation" , projects.wireGsonSupport)
220+ add(" jsonJavaTestImplementation" , projects.wireTestUtils)
221+ add(" jsonJavaTestImplementation" , libs.kotlin.test.junit)
222+ add(" jsonJavaTestImplementation" , libs.assertk)
223+ add(" jsonJavaTestImplementation" , libs.jimfs)
224+ add(" jsonJavaTestImplementation" , libs.truth)
225+ add(" jsonKotlinTestImplementation" , projects.wireMoshiAdapter)
226+ add(" jsonKotlinTestImplementation" , projects.wireGsonSupport)
227+ add(" jsonKotlinTestImplementation" , projects.wireTestUtils)
228+ add(" jsonKotlinTestImplementation" , libs.kotlin.test.junit)
229+ add(" jsonKotlinTestImplementation" , libs.assertk)
230+ add(" jsonKotlinTestImplementation" , libs.jimfs)
231+ add(" jsonKotlinTestImplementation" , libs.truth)
249232
250- add(" jvmJavaTestImplementation" , projects.wireMoshiAdapter)
251- add(" jvmJavaTestImplementation" , libs.kotlin.reflect)
252- add(" jvmJavaTestImplementation" , libs.moshi)
253- add(" jvmJavaTestImplementation" , libs.moshiKotlin)
254- }
255- }
233+ // add("jvmJavaTestImplementation", projects.wireMoshiAdapter)
234+ // add("jvmJavaTestImplementation", libs.kotlin.reflect)
235+ // add("jvmJavaTestImplementation", libs.moshi)
236+ // add("jvmJavaTestImplementation", libs.moshiKotlin)
256237}
257238
258239configure<SpotlessExtension > {
0 commit comments