Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtimeOnly and compileOnly configurations to Kotlin testing #106

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
Loading