Skip to content

Commit 7f05669

Browse files
authored
Use Kotlin DSL for gradle scripts (fwcd#81)
* Use Kotlin DSL for gradle scripts * Made the shared module import work with latest kotlin-language-server main * Add java version specifier to build pipeline * Experiment with disabling daemon for test invoking gradle * Remove copy-paste from kotlin language server
1 parent 3b09a57 commit 7f05669

File tree

7 files changed

+111
-66
lines changed

7 files changed

+111
-66
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
distribution: 'temurin'
2222
java-version: ${{ matrix.java }}
2323
- name: Build
24-
run: ./gradlew :adapter:build
24+
run: ./gradlew :adapter:build -PjavaVersion=${{ matrix.java }}

adapter/build.gradle

-48
This file was deleted.

adapter/build.gradle.kts

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
plugins {
2+
kotlin("jvm")
3+
id("maven-publish")
4+
id("application")
5+
id("com.jaredsburrows.license")
6+
}
7+
8+
val debugPort = 8000
9+
val debugArgs = "-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n,quiet=y"
10+
11+
val adapterMainClassName = "org.javacs.ktda.KDAMainKt"
12+
13+
application {
14+
mainClass.set(adapterMainClassName)
15+
description = "Debug Adapter for Kotlin"
16+
applicationDistribution.into("bin") {
17+
fileMode = 755
18+
}
19+
}
20+
21+
dependencies {
22+
// The JSON-RPC and Debug Adapter Protocol implementations
23+
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j.debug:0.15.0")
24+
implementation("org.jetbrains.kotlin:kotlin-stdlib")
25+
implementation("org.jetbrains.kotlin:kotlin-reflect")
26+
implementation("kotlin-language-server:shared")
27+
28+
// modules temporarily needed because of shared module import above
29+
implementation("org.jetbrains.exposed:exposed-core:0.37.3")
30+
implementation("org.jetbrains.exposed:exposed-dao:0.37.3")
31+
32+
33+
testImplementation("junit:junit:4.12")
34+
testImplementation("org.hamcrest:hamcrest-all:1.3")
35+
}
36+
37+
tasks.startScripts {
38+
applicationName = "kotlin-debug-adapter"
39+
}
40+
41+
tasks.register<Exec>("fixFilePermissions") {
42+
// When running on macOS or Linux the start script
43+
// needs executable permissions to run.
44+
45+
onlyIf { !System.getProperty("os.name").lowercase().contains("windows") }
46+
commandLine("chmod", "+x", "${tasks.installDist.get().destinationDir}/bin/kotlin-debug-adapter")
47+
}
48+
49+
tasks.register<JavaExec>("debugRun") {
50+
mainClass.set(adapterMainClassName)
51+
classpath(sourceSets.main.get().runtimeClasspath)
52+
standardInput = System.`in`
53+
54+
jvmArgs(debugArgs)
55+
doLast {
56+
println("Using debug port $debugPort")
57+
}
58+
}
59+
60+
tasks.register<CreateStartScripts>("debugStartScripts") {
61+
applicationName = "kotlin-debug-adapter"
62+
mainClass.set(adapterMainClassName)
63+
outputDir = tasks.installDist.get().destinationDir.toPath().resolve("bin").toFile()
64+
classpath = tasks.startScripts.get().classpath
65+
defaultJvmOpts = listOf(debugArgs)
66+
}
67+
68+
tasks.register<Sync>("installDebugDist") {
69+
dependsOn("installDist")
70+
finalizedBy("debugStartScripts")
71+
}
72+
73+
tasks.withType<Test>() {
74+
testLogging {
75+
events("failed")
76+
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.SHORT
77+
}
78+
}
79+
80+
tasks.installDist {
81+
finalizedBy("fixFilePermissions")
82+
}
83+
84+
tasks.build {
85+
finalizedBy("installDist")
86+
}

adapter/src/test/kotlin/org/javacs/ktda/DebugAdapterTestFixture.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class DebugAdapterTestFixture(
2424

2525
@Before fun startDebugAdapter() {
2626
// Build the project first
27-
val process = ProcessBuilder("./gradlew", "assemble")
27+
val process = ProcessBuilder("./gradlew", "--no-daemon", "assemble")
2828
.directory(absoluteWorkspaceRoot.toFile())
2929
.inheritIO()
3030
.start()

build.gradle renamed to build.gradle.kts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
2-
id 'org.jetbrains.kotlin.jvm' version "$kotlinVersion"
2+
kotlin("jvm")
3+
`maven-publish`
34
}
45

56
allprojects {

settings.gradle

-15
This file was deleted.

settings.gradle.kts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
rootProject.name = "kotlin-debug-adapter"
2+
3+
include("adapter")
4+
5+
pluginManagement {
6+
repositories {
7+
gradlePluginPortal()
8+
}
9+
10+
plugins {
11+
val kotlinVersion: String by settings
12+
kotlin("jvm") version "$kotlinVersion" apply false
13+
id("com.jaredsburrows.license") version "0.8.42" apply false
14+
}
15+
}
16+
17+
sourceControl {
18+
gitRepository(java.net.URI.create("https://github.com/fwcd/kotlin-language-server.git")) {
19+
producesModule("kotlin-language-server:shared")
20+
}
21+
}

0 commit comments

Comments
 (0)