Skip to content

Commit

Permalink
Merge pull request #106 from gradle/tt/add-runtime-compiletime-only-t…
Browse files Browse the repository at this point in the history
…o-kotlin

Add runtimeOnly and compileOnly configurations to Kotlin testing
  • Loading branch information
tresat authored Jul 3, 2024
2 parents 3897132 + 2ef367b commit f3e8c6d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
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;

/**
* An application implemented using Kotlin and that targets a single JVM version.
*/
@Restricted
public interface KotlinJvmApplication extends HasJavaTarget, HasJvmApplication, HasCliExecutables {
@Nested
Testing getTesting();

@Configuring
default void testing(Action<? super Testing> action) {
action.execute(getTesting());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Project> {

public static final String KOTLIN_JVM_APPLICATION = "kotlinJvmApplication";
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
@Restricted
public interface KotlinTestDependencies extends Dependencies {
DependencyCollector getImplementation();
DependencyCollector getCompileOnly();
DependencyCollector getRuntimeOnly();
}

0 comments on commit f3e8c6d

Please sign in to comment.