From e4f476c09fdcd40185f9a7b814ca172cb8b352ad Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Wed, 1 Nov 2017 14:17:14 +0900 Subject: [PATCH] Kapt, Maven: Fix running with the non-clean build (KT-20816) Clean target directories for kapt stubs and generated source files. Filter out the compile destination directory from the classpath. --- .../kotlin/maven/K2JVMCompileMojo.java | 6 ++++- .../maven/kapt/KaptJVMCompilerMojo.java | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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 70c36bfe071..62939f1ba61 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 @@ -132,6 +132,10 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase getClasspath() { + return filterClassPath(project.getBasedir(), classpath); + } + @NotNull protected String getSourceSetName() { return AnnotationProcessingManager.COMPILE_SOURCE_SET_NAME; @@ -150,7 +154,7 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase classpathList = filterClassPath(project.getBasedir(), classpath); + List classpathList = getClasspath(); if (!classpathList.isEmpty()) { String classPathString = join(classpathList, File.pathSeparator); diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java index 2dc2a76435c..1c776c6160d 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.maven.K2JVMCompileMojo; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import static org.jetbrains.kotlin.maven.Util.joinArrays; import static org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager.*; @@ -129,6 +130,28 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo { return super.execCompiler(compiler, messageCollector, arguments, sourceRoots); } + @Override + protected List getSourceFilePaths() { + File generatedSourcesDirectory = getGeneratedSourcesDirectory(project, getSourceSetName()); + + return super.getSourceFilePaths() + .stream() + .filter(path -> !new File(path).equals(generatedSourcesDirectory)) + .collect(Collectors.toList()); + } + + @Override + protected List getClasspath() { + File compileTargetDirectory = new File(this.output); + + // TODO it seems for me that the target directory should not be in the compile classpath + // We filter out it here, but it's definitely a work-around. + return super.getClasspath() + .stream() + .filter(path -> !new File(path).equals(compileTargetDirectory)) + .collect(Collectors.toList()); + } + protected void addKaptSourcesDirectory(@NotNull String path) { project.addCompileSourceRoot(path); }