Skip to content

Commit 4284103

Browse files
committed
fix project build
1 parent bc957af commit 4284103

File tree

11 files changed

+129
-65
lines changed

11 files changed

+129
-65
lines changed

Readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ This is an example project that shows how to create a Kotlin Compiler Plugin. At
2828
> :information_source: Please be aware that the Kotlin Compiler still doesn’t have any stable API and there is no
2929
> backwards compatibility guaranteed. Kotlin versions above 1.8.0 can have a totally different API.
3030
31-
* Inside the project folder run ` ./gradlew clean kotlin-plugin:publishToMavenLocal build`
31+
* Inside the project folder run ` ./gradlew clean build`
3232

3333
The plugin is only active when the build cache is changed. This is why you need to run "clean" before building, when you want to see the log output again.
3434

3535
### 👷 Project Structure
36-
* <kbd>lib</kbd> - A Kotlin Multiplatform project which applies a gradle plugin(compiler.plugin.helloworld) whichs triggers the compiler plugin.
37-
* <kbd>kotlin-compiler-plugin</kbd> - This module contains the Kotlin Compiler Plugin
36+
* <kbd>lib</kbd> - A Kotlin Multiplatform project which applies a gradle plugin(compiler.plugin.helloworld) whichs triggers the compiler plugin.
37+
* <kbd>compiler-plugin</kbd> - This module contains the Kotlin Compiler Plugin
3838
* <kbd>gradle-plugin</kbd> - This module contains the gradle plugin which trigger the compiler plugin
39-
*
39+
4040
## Useful resources
4141
[The Road to the New Kotlin Compiler](https://www.youtube.com/watch?v=iTdJJq_LyoY)
4242

build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ buildscript {
77
}
88

99
dependencies {
10+
classpath("com.vanniktech:gradle-maven-publish-plugin:0.23.1")
11+
1012
classpath("de.jensklingenberg:gradle-plugin:1.0.0")
1113
}
1214
}
File renamed without changes.

compiler-plugin/build.gradle.kts

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
4+
plugins {
5+
kotlin("jvm") version("1.8.0")
6+
kotlin("kapt") version("1.8.0")
7+
id("com.vanniktech.maven.publish") version("0.23.1")
8+
`maven-publish`
9+
signing
10+
11+
}
12+
13+
allprojects {
14+
repositories {
15+
mavenLocal()
16+
mavenCentral()
17+
maven("https://maven.google.com")
18+
maven("https://plugins.gradle.org/m2/")
19+
google()
20+
}
21+
}
22+
mavenPublishing {
23+
publishToMavenCentral()
24+
25+
}
26+
27+
group = "de.jensklingenberg"
28+
version = "0.0.1"
29+
val autoService = "1.0.1"
30+
dependencies {
31+
compileOnly("com.google.auto.service:auto-service:$autoService")
32+
kapt("com.google.auto.service:auto-service:$autoService")
33+
compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.8.0")
34+
testImplementation("dev.zacsweers.kctfork:core:0.2.1")
35+
testImplementation("junit:junit:4.13.2")
36+
testImplementation("com.google.truth:truth:1.1.3")
37+
testImplementation(kotlin("reflect"))
38+
39+
}
40+
41+
tasks.register("sourcesJar", Jar::class) {
42+
group = "build"
43+
description = "Assembles Kotlin sources"
44+
45+
archiveClassifier.set("sources")
46+
from(sourceSets.main.get().allSource)
47+
dependsOn(tasks.classes)
48+
}
49+
50+
publishing {
51+
publications {
52+
create<MavenPublication>("default") {
53+
from(components["java"])
54+
artifact(tasks["sourcesJar"])
55+
56+
pom {
57+
name.set("compiler-plugin")
58+
description.set("Hello World Compiler Plugin")
59+
url.set("https://github.com/Foso/KotlinCompilerPluginExample")
60+
61+
licenses {
62+
license {
63+
name.set("Apache License 2.0")
64+
url.set("https://github.com/Foso/KotlinCompilerPluginExample/blob/master/LICENSE.txt")
65+
}
66+
}
67+
scm {
68+
url.set("https://github.com/Foso/KotlinCompilerPluginExample")
69+
connection.set("scm:git:git://github.com/Foso/KotlinCompilerPluginExample.git")
70+
}
71+
developers {
72+
developer {
73+
name.set("Developer Name")
74+
url.set("Developer URL")
75+
}
76+
}
77+
}
78+
}
79+
}
80+
81+
repositories {
82+
if (
83+
hasProperty("sonatypeUsername") &&
84+
hasProperty("sonatypePassword") &&
85+
hasProperty("sonatypeSnapshotUrl") &&
86+
hasProperty("sonatypeReleaseUrl")
87+
) {
88+
maven {
89+
val url = when {
90+
"SNAPSHOT" in version.toString() -> property("sonatypeSnapshotUrl")
91+
else -> property("sonatypeReleaseUrl")
92+
} as String
93+
setUrl(url)
94+
credentials {
95+
username = property("sonatypeUsername") as String
96+
password = property("sonatypePassword") as String
97+
}
98+
}
99+
}
100+
}
101+
}
102+
103+
java {
104+
toolchain {
105+
languageVersion.set(JavaLanguageVersion.of(11))
106+
}
107+
}
108+
109+
tasks.withType<KotlinCompile> {
110+
kotlinOptions.jvmTarget = "1.8"
111+
}
112+
tasks.withType<KotlinCompilationTask<*>>().configureEach {
113+
compilerOptions.freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
114+
}
115+

gradle-plugin/build.gradle.kts

+6
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,10 @@ publishing {
9393
}
9494
}
9595
}
96+
}
97+
98+
99+
tasks.build {
100+
dependsOn(":kotlin-plugin:publishToMavenLocal")
101+
96102
}

gradle-plugin/src/main/java/de/jensklingenberg/gradle/HelloWorldGradleSubplugin.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class HelloWorldGradleSubPlugin : KotlinCompilerPluginSupportPlugin {
1515

1616
companion object {
1717
const val SERIALIZATION_GROUP_NAME = "de.jensklingenberg"
18-
const val ARTIFACT_NAME = "helloworld-compiler-plugin"
19-
const val NATIVE_ARTIFACT_NAME = "$ARTIFACT_NAME-native"
18+
const val ARTIFACT_NAME = "compiler-plugin"
2019
const val VERSION_NUMBER = "0.0.1"
2120
}
2221

kotlin-plugin/build.gradle

-53
This file was deleted.

lib/build.gradle.kts

-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,3 @@ kotlin {
3636
}
3737
}
3838

39-
40-
tasks.build {
41-
dependsOn(":kotlin-plugin:publishToMavenLocal")
42-
43-
}

settings.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ includeBuild("gradle-plugin") {
44
substitute(module("de.jensklingenberg:gradle-plugin:1.0.0")).using(project(":"))
55
}
66
}
7-
include(":kotlin-plugin")
7+
includeBuild("compiler-plugin")
88

99
include(":lib")

0 commit comments

Comments
 (0)