diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/annotation-processor/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/annotation-processor/pom.xml
new file mode 100644
index 00000000000..f8cb772b9ab
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/annotation-processor/pom.xml
@@ -0,0 +1,58 @@
+
+
+ 4.0.0
+
+ org.jetbrains.kotlin.testkapt
+ annotation-processor
+ 1.0-SNAPSHOT
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${kotlin.version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.1.2
+
+
+
+
+ ${project.basedir}/src/main/kotlin
+
+
+ kotlin-maven-plugin
+ org.jetbrains.kotlin
+ ${kotlin.version}
+
+
+ compile
+ process-sources
+
+ compile
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/annotation-processor/src/main/kotlin/ExampleAnnotationProcessor.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/annotation-processor/src/main/kotlin/ExampleAnnotationProcessor.kt
new file mode 100644
index 00000000000..d6fd9ee2f85
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/annotation-processor/src/main/kotlin/ExampleAnnotationProcessor.kt
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
+ * that can be found in the license/LICENSE.txt file.
+ */
+
+package example
+
+import java.io.File
+import javax.annotation.processing.AbstractProcessor
+import javax.annotation.processing.RoundEnvironment
+import javax.lang.model.SourceVersion
+import javax.lang.model.element.ElementKind
+import javax.lang.model.element.TypeElement
+import javax.tools.Diagnostic
+import kotlin.reflect.KClass
+
+annotation class Anno
+
+class ExampleAnnotationProcessor : AbstractProcessor() {
+ private companion object {
+ val KAPT_KOTLIN_GENERATED_OPTION = "kapt.kotlin.generated"
+ }
+
+ override fun process(annotations: MutableSet?, roundEnv: RoundEnvironment): Boolean {
+ val elements = roundEnv.getElementsAnnotatedWith(Anno::class.java)
+ val kotlinGenerated = processingEnv.options[KAPT_KOTLIN_GENERATED_OPTION]
+
+ for (element in elements) {
+ val packageName = processingEnv.elementUtils.getPackageOf(element).qualifiedName.toString()
+ val simpleName = element.simpleName.toString()
+
+ if (kotlinGenerated != null && element.kind == ElementKind.CLASS) {
+ File(kotlinGenerated, "$simpleName.kt").writer().buffered().use {
+ it.appendln("package $packageName")
+ it.appendln("fun $simpleName.customToString() = \"$simpleName: \" + toString()")
+ }
+ }
+ }
+
+ return true
+ }
+
+ override fun getSupportedSourceVersion() = SourceVersion.RELEASE_6
+ override fun getSupportedAnnotationTypes() = setOf(Anno::class.java.name)
+ override fun getSupportedOptions() = emptySet()
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/app/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/app/pom.xml
new file mode 100644
index 00000000000..e0a19ef008a
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/app/pom.xml
@@ -0,0 +1,73 @@
+
+
+
+ 4.0.0
+
+ org.jetbrains.kotlin.testkapt
+ app
+ 1.0-SNAPSHOT
+
+
+ 4.12
+ UTF-8
+
+
+
+
+ org.jetbrains.kotlin.testkapt
+ annotation-processor
+ 1.0-SNAPSHOT
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${kotlin.version}
+
+
+
+
+
+
+ kotlin-maven-plugin
+ org.jetbrains.kotlin
+ ${kotlin.version}
+
+
+ kapt
+
+ kapt
+
+
+
+ src/main/kotlin
+
+
+ example.ExampleAnnotationProcessor
+
+
+
+ org.jetbrains.kotlin.testkapt
+ annotation-processor
+ 1.0-SNAPSHOT
+
+
+
+
+
+ compile
+
+ compile
+
+
+
+ src/main/kotlin
+
+
+
+
+
+
+
+
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/app/src/main/kotlin/test.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/app/src/main/kotlin/test.kt
new file mode 100755
index 00000000000..c18d6a3057c
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/app/src/main/kotlin/test.kt
@@ -0,0 +1,8 @@
+package test
+
+@example.Anno
+class MyClass {
+ fun test() {
+ println(this.customToString())
+ }
+}
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/pom.xml
new file mode 100644
index 00000000000..3bc59529f32
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/pom.xml
@@ -0,0 +1,16 @@
+
+
+ 4.0.0
+
+ org.jetbrains.kotlin.testkapt
+ test-kapt-generateKotlinCode
+ 1.0-SNAPSHOT
+
+ annotation-processor
+ app
+
+ pom
+
+
\ No newline at end of file
diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/verify.bsh
new file mode 100644
index 00000000000..fbd96acd9af
--- /dev/null
+++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-kapt-generateKotlinCode/verify.bsh
@@ -0,0 +1,6 @@
+import java.io.*;
+
+File file = new File(basedir, "app/target/app-1.0-SNAPSHOT.jar");
+if (!file.exists() || !file.isFile()) {
+ throw new FileNotFoundException("Could not find generated JAR: " + 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 8c556df1b6c..2f6ea7d7458 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
@@ -123,14 +123,18 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase getSourceFilePaths() {
- List paths = super.getSourceFilePaths();
+ List paths = new ArrayList<>(super.getSourceFilePaths());
File sourcesDir = AnnotationProcessingManager.getGeneratedSourcesDirectory(project, getSourceSetName());
if (sourcesDir.isDirectory()) {
- paths = new ArrayList<>(paths);
paths.add(sourcesDir.getAbsolutePath());
}
+ File kotlinSourcesDir = AnnotationProcessingManager.getGeneratedKotlinSourcesDirectory(project, getSourceSetName());
+ if (kotlinSourcesDir.isDirectory()) {
+ paths.add(kotlinSourcesDir.getAbsolutePath());
+ }
+
return paths;
}
diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/AnnotationProcessingManager.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/AnnotationProcessingManager.java
index 483e71fd8f0..7cd072511e2 100644
--- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/AnnotationProcessingManager.java
+++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/AnnotationProcessingManager.java
@@ -77,6 +77,11 @@ public class AnnotationProcessingManager {
return new File(getTargetDirectory(project), "generated-sources/kapt/" + sourceSetName);
}
+ @NotNull
+ public static File getGeneratedKotlinSourcesDirectory(@NotNull MavenProject project, @NotNull String sourceSetName) {
+ return new File(getTargetDirectory(project), "generated-sources/kaptKotlin/" + sourceSetName);
+ }
+
@NotNull
static File getStubsDirectory(@NotNull MavenProject project, @NotNull String sourceSetName) {
return new File(getTargetDirectory(project), "kaptStubs/" + sourceSetName);
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 f0a1eb46eee..b14696af70d 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
@@ -110,20 +110,26 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo {
String sourceSetName = getSourceSetName();
File sourcesDirectory = getGeneratedSourcesDirectory(project, sourceSetName);
+ File kotlinSourcesDirectory = getGeneratedKotlinSourcesDirectory(project, sourceSetName);
File classesDirectory = getGeneratedClassesDirectory(project, sourceSetName);
File stubsDirectory = getStubsDirectory(project, sourceSetName);
addKaptSourcesDirectory(sourcesDirectory.getPath());
+ addKaptSourcesDirectory(kotlinSourcesDirectory.getPath());
mkdirsSafe(classesDirectory);
mkdirsSafe(stubsDirectory);
+ mkdirsSafe(kotlinSourcesDirectory);
options.add(new KaptOption("sources", sourcesDirectory.getAbsolutePath()));
options.add(new KaptOption("classes", classesDirectory.getAbsolutePath()));
options.add(new KaptOption("stubs", stubsDirectory.getAbsolutePath()));
options.add(new KaptOption("javacArguments", encodeOptionList(parseOptionList(javacOptions))));
- options.add(new KaptOption("apoptions", encodeOptionList(parseOptionList(annotationProcessorArgs))));
+
+ Map allApOptions = parseOptionList(annotationProcessorArgs);
+ allApOptions.put("kapt.kotlin.generated", kotlinSourcesDirectory.getAbsolutePath());
+ options.add(new KaptOption("apoptions", encodeOptionList(allApOptions)));
return options;
}
@@ -141,6 +147,7 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo {
String sourceSetName = getSourceSetName();
recreateDirectorySafe(getGeneratedSourcesDirectory(project, sourceSetName));
recreateDirectorySafe(getStubsDirectory(project, sourceSetName));
+ recreateDirectorySafe(getGeneratedKotlinSourcesDirectory(project, sourceSetName));
return super.execCompiler(compiler, messageCollector, arguments, sourceRoots);
}
@@ -148,10 +155,15 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo {
@Override
protected List getSourceFilePaths() {
File generatedSourcesDirectory = getGeneratedSourcesDirectory(project, getSourceSetName());
+ File generatedKotlinSourcesDirectory = getGeneratedKotlinSourcesDirectory(project, getSourceSetName());
return super.getSourceFilePaths()
.stream()
- .filter(path -> !new File(path).equals(generatedSourcesDirectory))
+ .filter(path -> {
+ File pathFile = new File(path);
+ return !pathFile.equals(generatedSourcesDirectory)
+ && !pathFile.equals(generatedKotlinSourcesDirectory);
+ })
.collect(Collectors.toList());
}