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.
This commit is contained in:
+5
-1
@@ -132,6 +132,10 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
|||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected List<String> getClasspath() {
|
||||||
|
return filterClassPath(project.getBasedir(), classpath);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected String getSourceSetName() {
|
protected String getSourceSetName() {
|
||||||
return AnnotationProcessingManager.COMPILE_SOURCE_SET_NAME;
|
return AnnotationProcessingManager.COMPILE_SOURCE_SET_NAME;
|
||||||
@@ -150,7 +154,7 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
|||||||
getLog().warn("Parameters module and testModule are deprecated and ignored, they will be removed in further release.");
|
getLog().warn("Parameters module and testModule are deprecated and ignored, they will be removed in further release.");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> classpathList = filterClassPath(project.getBasedir(), classpath);
|
List<String> classpathList = getClasspath();
|
||||||
|
|
||||||
if (!classpathList.isEmpty()) {
|
if (!classpathList.isEmpty()) {
|
||||||
String classPathString = join(classpathList, File.pathSeparator);
|
String classPathString = join(classpathList, File.pathSeparator);
|
||||||
|
|||||||
+23
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.maven.K2JVMCompileMojo;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.maven.Util.joinArrays;
|
import static org.jetbrains.kotlin.maven.Util.joinArrays;
|
||||||
import static org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager.*;
|
import static org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager.*;
|
||||||
@@ -129,6 +130,28 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo {
|
|||||||
return super.execCompiler(compiler, messageCollector, arguments, sourceRoots);
|
return super.execCompiler(compiler, messageCollector, arguments, sourceRoots);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<String> getSourceFilePaths() {
|
||||||
|
File generatedSourcesDirectory = getGeneratedSourcesDirectory(project, getSourceSetName());
|
||||||
|
|
||||||
|
return super.getSourceFilePaths()
|
||||||
|
.stream()
|
||||||
|
.filter(path -> !new File(path).equals(generatedSourcesDirectory))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<String> 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) {
|
protected void addKaptSourcesDirectory(@NotNull String path) {
|
||||||
project.addCompileSourceRoot(path);
|
project.addCompileSourceRoot(path);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user