[Maven] Fix Kotlin IC caches dir per source set Fix KT-78201 mistakenly configured the IC cache dir for classes to be outside the source set IC cache dir, allowing overriding output of one source set by output of a different source set which is incorrect. ^KT-81681 Verification Pending (cherry picked from commit 5be3bcabf280c9e0d5612a22b71e62cb8ee01be0)
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/test/java/org.jetbrains.kotlin.maven/IncrementalCompilationIT.java b/libraries/tools/kotlin-maven-plugin-test/src/test/java/org.jetbrains.kotlin.maven/IncrementalCompilationIT.java index 1d94eb5..80fb9e8 100644 --- a/libraries/tools/kotlin-maven-plugin-test/src/test/java/org.jetbrains.kotlin.maven/IncrementalCompilationIT.java +++ b/libraries/tools/kotlin-maven-plugin-test/src/test/java/org.jetbrains.kotlin.maven/IncrementalCompilationIT.java
@@ -44,6 +44,14 @@ }; } + @NotNull + private String[] withJavaOutputPaths() { + return new String[]{ + "target/classes/SomeMain.class", + "target/test-classes/SomeTests.class" + }; + } + @Test public void testNoChanges() throws Exception { MavenProject project = new MavenProject("kotlinSimple"); @@ -106,4 +114,15 @@ .filesExist(kotlinSimpleOutputPaths()) .compiledKotlin("src/main/kotlin/A.kt"); } + + @Test // Regression test for KT-81681 + public void secondRunWithTests() throws Exception { + MavenProject project = new MavenProject("kotlinWithTests"); + project.exec(executionStrategy, "package"); + + project.exec(executionStrategy, "package", "-X") + .succeeded() + .filesExist(withJavaOutputPaths()) + .compiledKotlin(); + } }
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/test/resources/kotlinWithTests/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/test/resources/kotlinWithTests/pom.xml new file mode 100644 index 0000000..5b0bc25 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/test/resources/kotlinWithTests/pom.xml
@@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>test-kotlin-incremental</artifactId> + <version>1.0-SNAPSHOT</version> + + <properties> + <kotlin.compiler.incremental>true</kotlin.compiler.incremental> + </properties> + + <dependencies> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib</artifactId> + <version>${kotlin.version}</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.13.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <version>2.1.2</version> + </plugin> + </plugins> + </pluginManagement> + + <plugins> + <plugin> + <artifactId>kotlin-maven-plugin</artifactId> + <groupId>org.jetbrains.kotlin</groupId> + <version>${kotlin.version}</version> + <executions> + <execution> + <id>compile</id> + <goals> <goal>compile</goal> </goals> + <configuration> + <sourceDirs> + <sourceDir>${project.basedir}/src/main/kotlin</sourceDir> + <sourceDir>${project.basedir}/src/main/java</sourceDir> + </sourceDirs> + </configuration> + </execution> + <execution> + <id>test-compile</id> + <goals> <goal>test-compile</goal> </goals> + <configuration> + <sourceDirs> + <sourceDir>${project.basedir}/src/test/kotlin</sourceDir> + <sourceDir>${project.basedir}/src/test/java</sourceDir> + </sourceDirs> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.5.1</version> + <executions> + <!-- Replacing default-compile as it is treated specially by maven --> + <execution> + <id>default-compile</id> + <phase>none</phase> + </execution> + <!-- Replacing default-testCompile as it is treated specially by maven --> + <execution> + <id>default-testCompile</id> + <phase>none</phase> + </execution> + <execution> + <id>java-compile</id> + <phase>compile</phase> + <goals> <goal>compile</goal> </goals> + </execution> + <execution> + <id>java-test-compile</id> + <phase>test-compile</phase> + <goals> <goal>testCompile</goal> </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> \ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/test/resources/kotlinWithTests/src/main/kotlin/SomeMain.kt b/libraries/tools/kotlin-maven-plugin-test/src/test/resources/kotlinWithTests/src/main/kotlin/SomeMain.kt new file mode 100644 index 0000000..0dcd785 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/test/resources/kotlinWithTests/src/main/kotlin/SomeMain.kt
@@ -0,0 +1,2 @@ +class SomeMain { +} \ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/test/resources/kotlinWithTests/src/test/kotlin/SomeTests.kt b/libraries/tools/kotlin-maven-plugin-test/src/test/resources/kotlinWithTests/src/test/kotlin/SomeTests.kt new file mode 100644 index 0000000..37de97d --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/test/resources/kotlinWithTests/src/test/kotlin/SomeTests.kt
@@ -0,0 +1,8 @@ +import org.junit.Test + +class SomeTests { + @Test + fun myTest() { + + } +} \ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java index 59b9204..3c6be60 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java
@@ -135,7 +135,7 @@ @NotNull private Path getKotlinClassesCacheDir() { - return Paths.get(incrementalCachesRoot, "classes"); + return getCachesDir().resolve("classes"); } protected boolean isIncremental() {