Skip to content

Commit e6c7c09

Browse files
committed
chore: Move to Kotlin DSL for Gradle build scripts
This change refactors the Gradle build files to use the Kotlin DSL instead of Groovy. With this change, we have also added support for building the plugin for non-embedded Kotlin compilers.
1 parent aeeeceb commit e6c7c09

File tree

15 files changed

+249
-230
lines changed

15 files changed

+249
-230
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# kotlin-plugin-generated
2-
A Kotlin compiler plugin that annotates Kotlin-generated methods with `lombok.Generated` to signify to code analyzers
3-
that these methods have been generated by the compiler.
2+
A Kotlin compiler plugin that annotates Kotlin-generated methods with
3+
`lombok.Generated` to signify to code analyzers that these methods have been
4+
generated by the compiler.
45

56
## JaCoCo solution (new)
67
Please note that JaCoCo landed support for recognizing Kotlin-generated
@@ -21,7 +22,7 @@ To use the plugin, just apply the plugin in your `build.gradle`:
2122

2223
```groovy
2324
plugins {
24-
id 'nl.fabianm.kotlin.plugin.generated' version '1.3.0'
25+
id 'nl.fabianm.kotlin.plugin.generated' version '1.3.1'
2526
}
2627
```
2728

@@ -31,7 +32,7 @@ version you are using:
3132
| **Kotlin** | **Plugin** |
3233
|:----------:|:----------:|
3334
| 1.2.* | 1.0 |
34-
| 1.3.* | 1.3.0 |
35+
| 1.3.* | 1.3.1 |
3536

3637
You can optionally configure the plugin as shown below:
3738

@@ -46,5 +47,5 @@ kotlinGenerated {
4647
```
4748

4849
## License
49-
The code is released under the Apache version 2.0 license. See the
50-
`LICENSE.txt` file.
50+
The code is released under the Apache version 2.0 license. See the
51+
[LICENSE.txt](/LICENSE.txt) file.

build.gradle renamed to build.gradle.kts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17+
plugins {
18+
kotlin("jvm") version "1.3.31" apply false
19+
id("org.jlleitschuh.gradle.ktlint") version "7.4.0" apply false
20+
id("com.github.johnrengelman.shadow") version "5.0.0" apply false
21+
}
22+
1723
allprojects {
18-
group = 'nl.fabianm.kotlin.plugin.generated'
19-
version = '1.3.0'
24+
group = "nl.fabianm.kotlin.plugin.generated"
25+
version = "1.3.1"
2026

21-
ext {
22-
kotlin_version = '1.3.0'
23-
junit_jupiter_version = '5.3.1'
24-
junit_platform_version = '1.3.1'
25-
}
27+
extra["junitJupiterVersion"] = "5.4.2"
28+
extra["junitPlatformVersion"] = "1.4.2"
2629
}
27-

gradle/wrapper/gradle-wrapper.jar

-561 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env sh
22

3+
#
4+
# Copyright 2015 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
##############################################################################
420
##
521
## Gradle start up script for UN*X
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
2844
APP_BASE_NAME=`basename "$0"`
2945

3046
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31-
DEFAULT_JVM_OPTS=""
47+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
3248

3349
# Use the maximum available, or set MAX_FD != -1 to use that value.
3450
MAX_FD="maximum"

gradlew.bat

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
@rem
2+
@rem Copyright 2015 the original author or authors.
3+
@rem
4+
@rem Licensed under the Apache License, Version 2.0 (the "License");
5+
@rem you may not use this file except in compliance with the License.
6+
@rem You may obtain a copy of the License at
7+
@rem
8+
@rem http://www.apache.org/licenses/LICENSE-2.0
9+
@rem
10+
@rem Unless required by applicable law or agreed to in writing, software
11+
@rem distributed under the License is distributed on an "AS IS" BASIS,
12+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
@rem See the License for the specific language governing permissions and
14+
@rem limitations under the License.
15+
@rem
16+
117
@if "%DEBUG%" == "" @echo off
218
@rem ##########################################################################
319
@rem
@@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
1430
set APP_HOME=%DIRNAME%
1531

1632
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17-
set DEFAULT_JVM_OPTS=
33+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
1834

1935
@rem Find java.exe
2036
if defined JAVA_HOME goto findJavaFromJavaHome

plugin-compiler-tests/build.gradle

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2018 Fabian Mastenbroek.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
18+
19+
plugins {
20+
kotlin("jvm")
21+
id("org.jlleitschuh.gradle.ktlint")
22+
jacoco
23+
}
24+
25+
repositories {
26+
jcenter()
27+
}
28+
29+
dependencies {
30+
compile("org.jetbrains.kotlin:kotlin-stdlib")
31+
runtimeOnly(project(":plugin-compiler", configuration = "embeddable"))
32+
33+
val junitJupiterVersion: String by extra
34+
val junitPlatformVersion: String by extra
35+
36+
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
37+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
38+
testImplementation("org.junit.platform:junit-platform-launcher:$junitPlatformVersion")
39+
}
40+
41+
/* Compilation */
42+
tasks.withType<KotlinCompile> {
43+
kotlinOptions {
44+
// Obtain the path to the embeddable (shaded) compiler plugin via the runtime classpath
45+
val pluginJar = configurations.runtimeClasspath.get().first { it.name.startsWith("plugin-compiler") }
46+
47+
jvmTarget = "1.8"
48+
// We force the plugin to make the annotations visible at runtime
49+
freeCompilerArgs = listOf("-Xplugin=$pluginJar", "-P", "plugin:nl.fabianm.kotlin.plugin.generated:visible=true")
50+
}
51+
}
52+
53+
/* Test setup */
54+
tasks.test {
55+
useJUnitPlatform {}
56+
57+
testLogging {
58+
events("passed", "skipped", "failed")
59+
}
60+
61+
reports {
62+
html.isEnabled = true
63+
}
64+
}
65+
66+
tasks.jacocoTestReport {
67+
sourceSets(sourceSets.main.get(), sourceSets.test.get())
68+
}

plugin-compiler/build.gradle renamed to plugin-compiler/build.gradle.kts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
18+
1719
plugins {
18-
id "org.jetbrains.kotlin.jvm" version "1.3.0"
19-
id "org.jlleitschuh.gradle.ktlint" version "6.2.1"
20+
kotlin("jvm")
21+
id("org.jlleitschuh.gradle.ktlint")
22+
id("com.github.johnrengelman.shadow")
2023
}
2124

2225
description = "A compiler plugin for Kotlin that marks Kotlin-generated code with an annotation."
@@ -26,34 +29,24 @@ repositories {
2629
}
2730

2831
dependencies {
29-
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
30-
compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable"
31-
32-
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
33-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version"
34-
testRuntimeOnly "org.junit.platform:junit-platform-launcher:$junit_platform_version"
32+
compile(kotlin("stdlib"))
33+
compileOnly(kotlin("compiler"))
3534
}
3635

37-
compileKotlin {
36+
/* Compilation */
37+
tasks.withType<KotlinCompile> {
3838
kotlinOptions {
3939
jvmTarget = "1.8"
4040
}
4141
}
4242

43-
compileTestKotlin {
44-
kotlinOptions {
45-
jvmTarget = "1.8"
46-
}
43+
tasks.shadowJar {
44+
configurations = listOf()
45+
archiveClassifier.set("embeddable")
46+
relocate("com.intellij", "org.jetbrains.kotlin.com.intellij")
4747
}
4848

49-
test {
50-
useJUnitPlatform {}
51-
52-
testLogging {
53-
events 'passed', 'skipped', 'failed'
54-
}
55-
56-
reports {
57-
html.enabled = true
58-
}
49+
// Create embeddable configuration
50+
configurations.create("embeddable") {
51+
extendsFrom(configurations.shadow.get())
5952
}

plugin-compiler/src/main/kotlin/nl/fabianm/kotlin/plugin/generated/GeneratedClassBuilderInterceptorExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package nl.fabianm.kotlin.plugin.generated
1818

19+
import com.intellij.psi.PsiElement
1920
import jdk.internal.org.objectweb.asm.Type
2021
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
2122
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
2223
import org.jetbrains.kotlin.codegen.ClassBuilder
2324
import org.jetbrains.kotlin.codegen.ClassBuilderFactory
2425
import org.jetbrains.kotlin.codegen.DelegatingClassBuilder
2526
import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension
26-
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
2727
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
2828
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
2929
import org.jetbrains.kotlin.name.FqName

0 commit comments

Comments
 (0)