From f38e1b218dc3e0a042f6c7a94365a3c6a578f035 Mon Sep 17 00:00:00 2001 From: Joseph Walton Date: Thu, 16 Dec 2021 13:03:36 +1100 Subject: [PATCH] Scripting, maven: use getArtifacts to get the plugin's runtime classpath ..to correctly pass the dependencies in the ExecuteKotlinScriptMojo. #KT-50306 fixed Also add a test that a script has access to plugin-configured dependencies. If plugin/dependencies is populated, the extra artifacts should be made available when the script is run. This test uses 'junit' simply because it's commonly-used, but not already present, or shaded as part of another artifact. --- .../pom.xml | 50 +++++++++++++++++++ .../script.kts | 3 ++ .../verify.bsh | 3 ++ .../kotlin/maven/ExecuteKotlinScriptMojo.java | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/pom.xml create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/script.kts create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/verify.bsh diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/pom.xml new file mode 100644 index 00000000000..28e5824be27 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + org.jetbrains.kotlin + test-executeKotlinScriptWithDependencies + 1.0-SNAPSHOT + + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + + ${project.basedir}/src/main/kotlin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + execute-kotlin-script + compile + + script + + + script.kts + + + + + + + junit + junit + 4.13.1 + + + + + + + \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/script.kts b/libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/script.kts new file mode 100644 index 00000000000..2045aac7772 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/script.kts @@ -0,0 +1,3 @@ +import org.junit.Assert + +println("Dependency jar is: ${Assert::class.java.getProtectionDomain().getCodeSource().getLocation().getPath().replace(Regex(".*/"), "")}") diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/verify.bsh new file mode 100644 index 00000000000..8d7955afa4f --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-executeKotlinScriptWithDependencies/verify.bsh @@ -0,0 +1,3 @@ +source(new File(basedir, "../../../verify-common.bsh").getAbsolutePath()); + +assertBuildLogHasLine("Dependency jar is: junit-4.13.1.jar"); diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ExecuteKotlinScriptMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ExecuteKotlinScriptMojo.java index e85cb4f6c0a..75e19e986f4 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ExecuteKotlinScriptMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/ExecuteKotlinScriptMojo.java @@ -247,7 +247,7 @@ public class ExecuteKotlinScriptMojo extends AbstractMojo { } private List getThisPluginDependencies() { - return plugin.getDependencies().stream().map(this::getDependencyFile).collect(Collectors.toList()); + return plugin.getArtifacts().stream().map(this::getArtifactFile).collect(Collectors.toList()); } private File getThisPluginAsDependency() {