From 2ef367b632bf3d8be299cd1558749d2bcaf837b5 Mon Sep 17 00:00:00 2001 From: Tom Tresansky Date: Wed, 3 Jul 2024 10:16:11 -0400 Subject: [PATCH] Add runtimeOnly and compileOnly configurations to Kotlin testing 389713 --- .../api/experimental/kotlin/KotlinJvmApplication.java | 11 +++++++++++ .../kotlin/StandaloneKotlinJvmApplicationPlugin.java | 10 ++++++++++ .../kotlin/StandaloneKotlinJvmLibraryPlugin.java | 2 ++ .../kotlin/testing/KotlinTestDependencies.java | 2 ++ 4 files changed, 25 insertions(+) diff --git a/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/KotlinJvmApplication.java b/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/KotlinJvmApplication.java index 06f3e588..5c2972ce 100644 --- a/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/KotlinJvmApplication.java +++ b/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/KotlinJvmApplication.java @@ -1,8 +1,12 @@ package org.gradle.api.experimental.kotlin; +import org.gradle.api.Action; import org.gradle.api.experimental.common.HasCliExecutables; import org.gradle.api.experimental.jvm.HasJavaTarget; import org.gradle.api.experimental.jvm.HasJvmApplication; +import org.gradle.api.experimental.kotlin.testing.Testing; +import org.gradle.api.tasks.Nested; +import org.gradle.declarative.dsl.model.annotations.Configuring; import org.gradle.declarative.dsl.model.annotations.Restricted; /** @@ -10,4 +14,11 @@ */ @Restricted public interface KotlinJvmApplication extends HasJavaTarget, HasJvmApplication, HasCliExecutables { + @Nested + Testing getTesting(); + + @Configuring + default void testing(Action action) { + action.execute(getTesting()); + } } diff --git a/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/StandaloneKotlinJvmApplicationPlugin.java b/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/StandaloneKotlinJvmApplicationPlugin.java index 2161d92c..053bbcae 100644 --- a/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/StandaloneKotlinJvmApplicationPlugin.java +++ b/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/StandaloneKotlinJvmApplicationPlugin.java @@ -2,6 +2,7 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.experimental.common.CliApplicationConventionsPlugin; import org.gradle.api.experimental.jvm.internal.JvmPluginSupport; import org.gradle.api.experimental.kmp.internal.KotlinPluginSupport; @@ -12,6 +13,7 @@ * Creates a declarative {@link KotlinJvmApplication} DSL model, applies the official Kotlin and application plugin, * and links the declarative model to the official plugin. */ +@SuppressWarnings("UnstableApiUsage") abstract public class StandaloneKotlinJvmApplicationPlugin implements Plugin { public static final String KOTLIN_JVM_APPLICATION = "kotlinJvmApplication"; @@ -35,7 +37,15 @@ private void linkDslModelToPlugin(Project project, KotlinJvmApplication dslModel KotlinPluginSupport.linkJavaVersion(project, dslModel); JvmPluginSupport.linkApplicationMainClass(project, dslModel); JvmPluginSupport.linkMainSourceSourceSetDependencies(project, dslModel.getDependencies()); + configureTesting(project, dslModel); dslModel.getRunTasks().add(project.getTasks().named("run")); } + + private void configureTesting(Project project, KotlinJvmApplication dslModel) { + ConfigurationContainer configurations = project.getConfigurations(); + configurations.getByName("testImplementation").fromDependencyCollector(dslModel.getTesting().getDependencies().getImplementation()); + configurations.getByName("testCompileOnly").fromDependencyCollector(dslModel.getTesting().getDependencies().getCompileOnly()); + configurations.getByName("testRuntimeOnly").fromDependencyCollector(dslModel.getTesting().getDependencies().getRuntimeOnly()); + } } diff --git a/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/StandaloneKotlinJvmLibraryPlugin.java b/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/StandaloneKotlinJvmLibraryPlugin.java index 9f57dbd3..4b0fce0e 100644 --- a/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/StandaloneKotlinJvmLibraryPlugin.java +++ b/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/StandaloneKotlinJvmLibraryPlugin.java @@ -46,5 +46,7 @@ private void linkDslModelToPlugin(Project project, KotlinJvmLibrary dslModel) { private void configureTesting(Project project, KotlinJvmLibrary dslModel) { ConfigurationContainer configurations = project.getConfigurations(); configurations.getByName("testImplementation").fromDependencyCollector(dslModel.getTesting().getDependencies().getImplementation()); + configurations.getByName("testCompileOnly").fromDependencyCollector(dslModel.getTesting().getDependencies().getCompileOnly()); + configurations.getByName("testRuntimeOnly").fromDependencyCollector(dslModel.getTesting().getDependencies().getRuntimeOnly()); } } diff --git a/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/testing/KotlinTestDependencies.java b/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/testing/KotlinTestDependencies.java index 9e64184a..1194beb4 100644 --- a/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/testing/KotlinTestDependencies.java +++ b/unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kotlin/testing/KotlinTestDependencies.java @@ -24,4 +24,6 @@ @Restricted public interface KotlinTestDependencies extends Dependencies { DependencyCollector getImplementation(); + DependencyCollector getCompileOnly(); + DependencyCollector getRuntimeOnly(); }