forked from Strumenta/antlr-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
134 lines (118 loc) · 4.75 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// a small hack: the variable must be named like the property
// jitpack will pass -Pversion=..., so `val version` is required here.
val version: String by project
// we create an alias here...
val versionProperty = version
// do the same for group
val group: String by project
val groupProperty = if (group.endsWith(".antlr-kotlin")) {
group
} else {
// just another jitpack hack
"$group.antlr-kotlin"
}
//val antlrVersion = "4.7.1"
val antlrKotlinVersion = versionProperty
// you can also use a jitpack version:
//val antlrKotlinVersion = "86a86f1968"
buildscript {
// we have to re-declare this here :-(
// a small hack: the variable must be named like the property
// jitpack will pass -Pversion=..., so `val version` is required here.
val version: String by project
// we create an alias here...
val versionProperty = version
// do the same for group
val group: String by project
val groupProperty = if (group.endsWith(".antlr-kotlin")) {
group
} else {
// just another jitpack hack
"$group.antlr-kotlin"
}
val antlrKotlinVersion = versionProperty
// you can also use a jitpack version (we have to re-declare this here):
//val antlrKotlinVersion = "86a86f1968"
dependencies {
// add the plugin to the classpath
classpath("$groupProperty:antlr-kotlin-gradle-plugin:$antlrKotlinVersion")
}
}
repositories {
// used for local development and while building by travis ci and jitpack.io
mavenLocal()
// used to download antlr4
mavenCentral()
// used to download antlr-kotlin-runtime
maven("https://jitpack.io")
}
plugins {
kotlin("multiplatform") version "1.4.10"
// do not add the plugin here, it contains only a task
//id("com.strumenta.antlr-kotlin") version "0.0.5"
}
kotlin {
jvm()
sourceSets {
val commonAntlr by creating {
dependencies {
api(kotlin("stdlib-common"))
// add antlr-kotlin-runtime
// otherwise, the generated sources will not compile
api("$groupProperty:antlr-kotlin-runtime:$antlrKotlinVersion")
// antlr-kotlin-runtime-jvm is automatically added as an jvm dependency by gradle
}
// you have to add the generated sources the to the kotlin compiler source directory list
// this is not required if you use src/commonAntlr/kotlin
// and want to add the generated sources to version control
kotlin.srcDir("build/generated-src/commonAntlr/kotlin")
}
val commonMain by getting {
dependsOn(commonAntlr)
}
val jvmMain by getting {
dependencies {
api(kotlin("stdlib-jdk8"))
api(kotlin("reflect"))
}
}
val jvmTest by getting {
dependencies {
api(kotlin("test-junit5"))
}
}
}
}
// in antlr-kotlin-plugin <0.0.5, the configuration was applied by the plugin.
// starting from verison 0.0.5, you have to apply it manually:
tasks.register<com.strumenta.antlrkotlin.gradleplugin.AntlrKotlinTask>("generateKotlinCommonGrammarSource") {
// the classpath used to run antlr code generation
antlrClasspath = configurations.detachedConfiguration(
// antlr itself
// antlr is transitive added by antlr-kotlin-target,
// add another dependency if you want to choose another antlr4 version (not recommended)
// project.dependencies.create("org.antlr:antlr4:$antlrVersion"),
// antlr target, required to create kotlin code
project.dependencies.create("$groupProperty:antlr-kotlin-target:$antlrKotlinVersion")
)
maxHeapSize = "64m"
packageName = "com.strumenta.antlrkotlin.examples"
arguments = listOf("-no-visitor", "-no-listener")
source = project.objects
.sourceDirectorySet("antlr", "antlr")
.srcDir("src/commonAntlr/antlr").apply {
include("*.g4")
}
// outputDirectory is required, put it into the build directory
// if you do not want to add the generated sources to version control
outputDirectory = File("build/generated-src/commonAntlr/kotlin")
// use this settings if you want to add the generated sources to version control
// outputDirectory = File("src/commonAntlr/kotlin")
}
// run generate task before build
// not required if you add the generated sources to version control
// you can call the task manually in this case to update the generated sources
tasks.getByName("compileKotlinJvm").dependsOn("generateKotlinCommonGrammarSource")
// to allow -x jsIrBrowserTest -x jsLegacyBrowserTest, see .ci.sh
tasks.register("jsIrBrowserTest")
tasks.register("jsLegacyBrowserTest")