diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-enable-extensions-kapt-allopen/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-enable-extensions-kapt-allopen/pom.xml index 20ee11bf958..55b76b8f9cd 100644 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-enable-extensions-kapt-allopen/pom.xml +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-enable-extensions-kapt-allopen/pom.xml @@ -13,7 +13,6 @@ 4.13.1 coffee.CoffeeApp UTF-8 - 1.8.255-SNAPSHOT diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/app/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/app/pom.xml new file mode 100644 index 00000000000..c50fea7debd --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/app/pom.xml @@ -0,0 +1,59 @@ + + + + 4.0.0 + + org.jetbrains.kotlin + test-respect-compile-source-root-app + 1.0-SNAPSHOT + + + UTF-8 + + + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + + + + org.jetbrains.kotlin + add-custom-sourceRoots-maven-plugin + 0.0.1-SNAPSHOT + + + + add-custom-sourceRoots + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + compile + + compile + + + + src/main/kotlin + + + + + + + + diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/app/src/main/kotlin/test.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/app/src/main/kotlin/test.kt new file mode 100755 index 00000000000..b6b1387eb7f --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/app/src/main/kotlin/test.kt @@ -0,0 +1,3 @@ +fun foo(){ + println("1") +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/invoker.properties b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/invoker.properties new file mode 100644 index 00000000000..c21e972fc6b --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/invoker.properties @@ -0,0 +1 @@ +invoker.buildResult = failure diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/myPlugin/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/myPlugin/pom.xml new file mode 100644 index 00000000000..59e923ceefe --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/myPlugin/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + org.jetbrains.kotlin + add-custom-sourceRoots-maven-plugin + maven-plugin + 0.0.1-SNAPSHOT + + add-custom-sourceRoots-plugin Maven Mojo + http://maven.apache.org + + + 1.8 + 1.8 + + + + + org.apache.maven + maven-plugin-api + ${maven.version} + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.7.0 + provided + + + org.apache.maven + maven-core + ${maven.version} + + + diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/myPlugin/src/main/java/AddCustomSourceRootsMojo.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/myPlugin/src/main/java/AddCustomSourceRootsMojo.java new file mode 100644 index 00000000000..3bab68d416e --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/myPlugin/src/main/java/AddCustomSourceRootsMojo.java @@ -0,0 +1,44 @@ +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +import java.io.*; +import java.nio.file.Files; +import java.util.List; + +@Mojo(name = "add-custom-sourceRoots", defaultPhase = LifecyclePhase.COMPILE) +public class AddCustomSourceRootsMojo + extends AbstractMojo { + @Parameter(defaultValue = "${project}", required = true, readonly = true) + public MavenProject project; + + public void execute() + throws MojoExecutionException { + File targetGeneratedFolder = new File(project.getBasedir().getAbsolutePath(), "target/gen"); + if (!targetGeneratedFolder.exists()) { + if (!targetGeneratedFolder.mkdirs()) { + throw new MojoExecutionException("Failed to create target directory."); + } + } + File generatedKtFile = new File(targetGeneratedFolder, "new.kt"); + + try { + String str = "fun foo(){\n" + + " println(\"2\")\n" + + "}"; + BufferedWriter writer = new BufferedWriter(new FileWriter(generatedKtFile)); + writer.write(str); + writer.close(); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage()); + } + + getLog().info("path: " + generatedKtFile.getAbsolutePath()); + project.addCompileSourceRoot(targetGeneratedFolder.getAbsolutePath()); + getLog().info("CompileSourceRoots: " + project.getCompileSourceRoots().toString()); + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/pom.xml new file mode 100644 index 00000000000..7cc89ba28d8 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + org.jetbrains.kotlin + test-respect-compile-source-root + 1.0-SNAPSHOT + + myPlugin + app + + pom + + \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/verify.bsh new file mode 100644 index 00000000000..087f13e3c43 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-respect-compile-source-root/verify.bsh @@ -0,0 +1,4 @@ +source(new File(basedir, "../../../verify-common.bsh").getAbsolutePath()); + +assertBuildLogHasLine("[INFO] BUILD FAILURE"); +assertBuildLogHasLineThatContains("Conflicting overloads:"); \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java index cef833cb168..47aea69eb03 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java @@ -74,8 +74,10 @@ public abstract class KotlinCompileMojoBase e private boolean multiPlatform = false; protected List getSourceFilePaths() { - if (sourceDirs != null && !sourceDirs.isEmpty()) return sourceDirs; - return project.getCompileSourceRoots(); + List list = new ArrayList<>(); + if (sourceDirs != null && !sourceDirs.isEmpty()) list.addAll(sourceDirs); + list.addAll(project.getCompileSourceRoots()); + return list; } @NotNull