[lombok] Add maven plugin integration test with kapt
This commit is contained in:
committed by
TeamCityServer
parent
3e883120dd
commit
b88f54b31a
@@ -1,6 +1,4 @@
|
||||
import java.io.*;
|
||||
source(new File(basedir, "../../../verify-common.bsh").getAbsolutePath());
|
||||
|
||||
File file = new File(basedir, "target/test-lombok-simple-1.0-SNAPSHOT.jar");
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
throw new FileNotFoundException("Could not find generated JAR: " + file);
|
||||
}
|
||||
assertBuildLogHasLineThatContains("Applied plugin: 'kotlin-lombok'");
|
||||
assertFileExists("target/test-lombok-simple-1.0-SNAPSHOT.jar");
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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-lombok-with-kapt</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
|
||||
|
||||
<moshi.version>1.12.0</moshi.version>
|
||||
<lombok.version>1.18.20</lombok.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>mavenCentral</id>
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<configuration>
|
||||
<compilerPlugins>
|
||||
<plugin>kotlin-lombok</plugin>
|
||||
</compilerPlugins>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>kapt</id>
|
||||
<goals>
|
||||
<goal>kapt</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
|
||||
<sourceDir>${project.basedir}/src/main/java</sourceDir>
|
||||
</sourceDirs>
|
||||
<annotationProcessorPaths>
|
||||
<annotationProcessorPath>
|
||||
<groupId>com.squareup.moshi</groupId>
|
||||
<artifactId>moshi-kotlin-codegen</artifactId>
|
||||
<version>${moshi.version}</version>
|
||||
</annotationProcessorPath>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
<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>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-lombok</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<annotationProcessorPath>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</annotationProcessorPath>
|
||||
</annotationProcessorPaths>
|
||||
</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>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.moshi</groupId>
|
||||
<artifactId>moshi-kotlin</artifactId>
|
||||
<version>${moshi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package lab2;
|
||||
|
||||
public class JavaUsage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SomePojo obj = new SomePojo();
|
||||
obj.setAge(12);
|
||||
boolean v = obj.isHuman();
|
||||
obj.setHuman(!v);
|
||||
System.out.println(obj);
|
||||
}
|
||||
|
||||
public static void cycleUsage() {
|
||||
new SomeKotlinClass().call();
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package lab2;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ManualPojo {
|
||||
|
||||
public String getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// @NotNull
|
||||
public String getBar() {
|
||||
return "234";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object someMethod() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package lab2;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SomeData {
|
||||
private String name;
|
||||
private int age;
|
||||
private boolean human;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package lab2;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter @Setter @ToString
|
||||
public class SomePojo {
|
||||
|
||||
@NonNull
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
private boolean human;
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package lab2
|
||||
|
||||
fun main() {
|
||||
println("something")
|
||||
val obj = SomePojo()
|
||||
obj.name = "test"
|
||||
val s: String = obj.name
|
||||
obj.age = 12
|
||||
val v = obj.isHuman
|
||||
obj.isHuman = !v
|
||||
println(obj)
|
||||
//
|
||||
// val manualPojo = ManualPojo()
|
||||
//
|
||||
// val foo: String? = manualPojo.getFoo()
|
||||
// val res: Any? = manualPojo.someMethod()
|
||||
//
|
||||
val ddd = SomeData()
|
||||
|
||||
JavaUsage.cycleUsage()
|
||||
}
|
||||
|
||||
class SomeKotlinClass {
|
||||
fun call() {
|
||||
val ddd = SomeData()
|
||||
ddd.age = 12
|
||||
println(ddd)
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package lab2
|
||||
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.squareup.moshi.Moshi
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class SomeObj(
|
||||
val hidden: Boolean,
|
||||
val names: List<String>
|
||||
)
|
||||
|
||||
fun main() {
|
||||
|
||||
val json = """
|
||||
{
|
||||
"hidden": true,
|
||||
"names": ["a", "b"]
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val moshi: Moshi = Moshi.Builder().build()
|
||||
val adapter = moshi.adapter(SomeObj::class.java)
|
||||
println(adapter.fromJson(json))
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
source(new File(basedir, "../../../verify-common.bsh").getAbsolutePath());
|
||||
|
||||
assertBuildLogHasLineThatContains("Applied plugin: 'kotlin-lombok'");
|
||||
assertFileExists("target/test-lombok-with-kapt-1.0-SNAPSHOT.jar");
|
||||
assertFileExists("target/kaptStubs/compile/lab2/SomeObj.java");
|
||||
assertFileExists("target/generated-sources/kapt/compile/lab2/SomeObjJsonAdapter.kt");
|
||||
|
||||
@@ -66,4 +66,11 @@ int findLineThatContains(String[] lines, String content) {
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void assertFileExists(String relativePath) {
|
||||
File file = new File(basedir, relativePath);
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
throw new Exception("Expected file not found: " + relativePath);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -64,7 +64,13 @@ class LombokCommandLineProcessor : CommandLineProcessor {
|
||||
|
||||
override fun processOption(option: AbstractCliOption, value: String, configuration: CompilerConfiguration) {
|
||||
when (option) {
|
||||
CONFIG_FILE_OPTION -> configuration.put(CONFIG_FILE, File(value))
|
||||
CONFIG_FILE_OPTION -> {
|
||||
val file = File(value)
|
||||
if (!file.exists()) {
|
||||
throw IllegalArgumentException("Config file not found ${file.absolutePath}")
|
||||
}
|
||||
configuration.put(CONFIG_FILE, file)
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unknown option $option")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user