Kapt: Preserve kapt plugin options if there are also options from compiler plugins (KT-20257)
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.jetbrains.kotlin.examples</groupId>
|
||||
<artifactId>dagger-maven-example</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<junit.version>4.12</junit.version>
|
||||
<main.class>coffee.CoffeeApp</main.class>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.dagger</groupId>
|
||||
<artifactId>dagger</artifactId>
|
||||
<version>2.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
|
||||
<configuration>
|
||||
<compilerPlugins>
|
||||
<plugin>all-open</plugin>
|
||||
</compilerPlugins>
|
||||
<pluginOptions>
|
||||
<option>all-open:annotation=coffee.AllOpen</option>
|
||||
</pluginOptions>
|
||||
</configuration>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-allopen</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>kapt</id>
|
||||
<goals>
|
||||
<goal>kapt</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>src/main/kotlin</sourceDir>
|
||||
<sourceDir>src/main/java</sourceDir>
|
||||
</sourceDirs>
|
||||
<annotationProcessorPaths>
|
||||
<annotationProcessorPath>
|
||||
<groupId>com.google.dagger</groupId>
|
||||
<artifactId>dagger-compiler</artifactId>
|
||||
<version>2.9</version>
|
||||
</annotationProcessorPath>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>src/main/kotlin</sourceDir>
|
||||
<sourceDir>src/main/java</sourceDir>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-kapt</id>
|
||||
<goals>
|
||||
<goal>test-kapt</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>src/test/kotlin</sourceDir>
|
||||
<sourceDir>src/test/java</sourceDir>
|
||||
</sourceDirs>
|
||||
<annotationProcessorPaths>
|
||||
<annotationProcessorPath>
|
||||
<groupId>com.google.dagger</groupId>
|
||||
<artifactId>dagger-compiler</artifactId>
|
||||
<version>2.9</version>
|
||||
</annotationProcessorPath>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>src/test/kotlin</sourceDir>
|
||||
<sourceDir>src/test/java</sourceDir>
|
||||
<sourceDir>target/generated-sources/kapt/test</sourceDir>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<proc>none</proc>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
<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>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package coffee
|
||||
|
||||
annotation class AllOpen
|
||||
|
||||
@AllOpen
|
||||
class MyClass
|
||||
|
||||
class MyClass2 : MyClass()
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
package coffee
|
||||
|
||||
import dagger.Component
|
||||
import javax.inject.Singleton
|
||||
|
||||
object CoffeeApp {
|
||||
@Singleton
|
||||
@Component(modules = arrayOf(DripCoffeeModule::class))
|
||||
interface Coffee {
|
||||
fun maker(): CoffeeMaker
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
val coffee = DaggerCoffeeApp_Coffee.builder().build()
|
||||
coffee.maker().brew()
|
||||
}
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
package coffee
|
||||
|
||||
import dagger.Lazy
|
||||
import javax.inject.Inject
|
||||
|
||||
class CoffeeMaker @Inject constructor(
|
||||
private val heater: Lazy<Heater>,
|
||||
private val pump: Pump
|
||||
) {
|
||||
|
||||
fun brew() {
|
||||
heater.get().on()
|
||||
pump.pump()
|
||||
println(" [_]P coffee! [_]P ")
|
||||
heater.get().off()
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package coffee
|
||||
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module(includes = arrayOf(PumpModule::class))
|
||||
class DripCoffeeModule {
|
||||
@Provides @Singleton
|
||||
fun provideHeater(): Heater {
|
||||
return ElectricHeater()
|
||||
}
|
||||
}
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
package coffee
|
||||
|
||||
open class ElectricHeater : Heater {
|
||||
override var isHot: Boolean = false
|
||||
|
||||
override fun on() {
|
||||
println("~ ~ ~ heating ~ ~ ~")
|
||||
this.isHot = true
|
||||
}
|
||||
|
||||
override fun off() {
|
||||
this.isHot = false
|
||||
}
|
||||
}
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
package coffee
|
||||
|
||||
interface Heater {
|
||||
fun on()
|
||||
fun off()
|
||||
val isHot: Boolean
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
package coffee
|
||||
|
||||
interface Pump {
|
||||
fun pump()
|
||||
}
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
package coffee
|
||||
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
|
||||
@Module
|
||||
abstract class PumpModule {
|
||||
@Binds
|
||||
abstract fun providePump(pump: Thermosiphon): Pump
|
||||
}
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
package coffee
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
class Thermosiphon @Inject
|
||||
constructor(private val heater: Heater) : Pump {
|
||||
override fun pump() {
|
||||
if (heater.isHot) {
|
||||
println("=> => pumping => =>")
|
||||
}
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package hello.tests
|
||||
|
||||
import coffee.*
|
||||
import dagger.Component
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import junit.framework.TestCase
|
||||
import javax.inject.Singleton
|
||||
|
||||
private var executed = false
|
||||
|
||||
class ExampleTest : TestCase() {
|
||||
@Singleton
|
||||
@Component(modules = arrayOf(TestCoffeeModule::class))
|
||||
interface Coffee {
|
||||
fun maker(): CoffeeMaker
|
||||
}
|
||||
|
||||
@Module(includes = arrayOf(PumpModule::class))
|
||||
class TestCoffeeModule {
|
||||
@Provides @Singleton
|
||||
fun provideHeater(): Heater {
|
||||
return object: ElectricHeater() {
|
||||
override fun on() {
|
||||
println("~ psh ~ psh ~ psh ~")
|
||||
println("(from tests)")
|
||||
executed = true
|
||||
super.on()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun testAssert() {
|
||||
val coffee = DaggerExampleTest_Coffee.builder().build()
|
||||
coffee.maker().brew()
|
||||
assert(executed)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.io.*;
|
||||
|
||||
File file = new File(basedir, "target/dagger-maven-example-1.0-SNAPSHOT.jar");
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
throw new FileNotFoundException("Could not find generated JAR: " + file);
|
||||
}
|
||||
|
||||
File generatedFile = new File(baseDir, "target/generated-sources/kapt/compile/coffee/CoffeeMaker_Factory.java");
|
||||
if (!generatedFile.exists() || !generatedFile.isFile()) {
|
||||
throw new FileNotFoundException("Kapt was not executed, file is absent: " + generatedFile);
|
||||
}
|
||||
+5
-1
@@ -51,6 +51,8 @@ import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.jetbrains.kotlin.maven.Util.joinArrays;
|
||||
|
||||
public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> extends AbstractMojo {
|
||||
@Component
|
||||
protected PlexusContainer container;
|
||||
@@ -494,7 +496,9 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
||||
getLog().debug("Plugin options are: " + Joiner.on(", ").join(pluginArguments));
|
||||
}
|
||||
|
||||
arguments.setPluginOptions(pluginArguments.toArray(new String[pluginArguments.size()]));
|
||||
arguments.setPluginOptions(joinArrays(
|
||||
arguments.getPluginOptions(),
|
||||
pluginArguments.toArray(new String[pluginArguments.size()])));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.maven;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -26,4 +29,21 @@ public class Util {
|
||||
new File(s).exists() || new File(basedir, s).exists()
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String[] joinArrays(@Nullable String[] first, @Nullable String[] second) {
|
||||
if (first == null) {
|
||||
first = new String[0];
|
||||
}
|
||||
if (second == null) {
|
||||
second = new String[0];
|
||||
}
|
||||
|
||||
String[] result = new String[first.length + second.length];
|
||||
|
||||
System.arraycopy(first, 0, result, 0, first.length);
|
||||
System.arraycopy(second, 0, result, first.length, second.length);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-17
@@ -31,6 +31,7 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.maven.Util.joinArrays;
|
||||
import static org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager.*;
|
||||
|
||||
/** @noinspection UnusedDeclaration */
|
||||
@@ -182,23 +183,6 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String[] joinArrays(@Nullable String[] first, @Nullable String[] second) {
|
||||
if (first == null) {
|
||||
first = new String[0];
|
||||
}
|
||||
if (second == null) {
|
||||
second = new String[0];
|
||||
}
|
||||
|
||||
String[] result = new String[first.length + second.length];
|
||||
|
||||
System.arraycopy(first, 0, result, 0, first.length);
|
||||
System.arraycopy(second, 0, result, first.length, second.length);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isIncremental() {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user