forked from open-policy-agent/opa-idea-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
145 lines (115 loc) · 3.49 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
135
136
137
138
139
140
141
142
143
144
145
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/
import org.gradle.api.JavaVersion.VERSION_1_8
import org.gradle.api.internal.HasConvention
import org.jetbrains.grammarkit.tasks.GenerateLexer
import org.jetbrains.grammarkit.tasks.GenerateParser
import org.jetbrains.intellij.tasks.RunIdeTask
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val ideaVersion = prop("ideaVersion")
val psiViewerPluginVersion = prop("psiViewerPluginVersion")
plugins {
idea
kotlin("jvm") version "1.3.50"
id("org.jetbrains.intellij") version "0.4.16"
id("org.jetbrains.grammarkit") version "2020.1"
id("de.undercouch.download") version "3.4.3"
id("net.saliman.properties") version "1.4.6"
}
apply {
plugin("idea")
plugin("kotlin")
plugin("org.jetbrains.grammarkit")
plugin("org.jetbrains.intellij")
}
group = "org.openpolicyagent"
version = "1.0.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.assertj:assertj-core:3.16.1")
}
idea {
module {
generatedSourceDirs.add(file("src/main/gen"))
// https://github.com/gradle/kotlin-dsl/issues/537/
excludeDirs = excludeDirs + file("testData") + file("deps")
}
}
intellij {
version = ideaVersion
val plugins = mutableListOf(
"PsiViewer:$psiViewerPluginVersion",
"java"
)
tasks{
withType<org.jetbrains.intellij.tasks.PatchPluginXmlTask> {
sinceBuild(prop("sinceBuild"))
untilBuild(prop("untilBuild"))
}
}
setPlugins(*plugins.toTypedArray())
}
sourceSets {
main {
java.srcDirs("src/main/gen")
kotlin.srcDirs("src/main/kotlin")
resources.srcDirs("src/main/resources")
}
test {
kotlin.srcDirs("src/test/kotlin")
resources.srcDirs("src/test/resources")
}
}
configure<JavaPluginConvention> {
sourceCompatibility = VERSION_1_8
targetCompatibility = VERSION_1_8
}
tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
languageVersion = "1.3"
apiVersion = "1.3"
freeCompilerArgs = listOf("-Xjvm-default=enable")
}
}
withType<RunIdeTask> {
jvmArgs("--add-exports", "java.base/jdk.internal.vm=ALL-UNNAMED")
}
}
val generateRegoLexer = task<GenerateLexer>("generateRegoLexer") {
source = "src/main/grammar/RegoLexer.flex"
targetDir = "src/main/gen/org/openpolicyagent/ideaplugin/lang/lexer"
targetClass = "_RegoLexer"
purgeOldFiles = true
}
val generateRegoParser = task<GenerateParser>("generateRegoParser") {
source = "src/main/grammar/Rego.bnf"
targetRoot = "src/main/gen"
pathToParser = "/org/openpolicyagent/ideaplugin/lang/parser/RegoParser.java"
pathToPsiRoot = "/org/openpolicyagent/ideaplugin/lang/psi"
purgeOldFiles = true
}
tasks.withType<KotlinCompile> {
dependsOn(
generateRegoLexer,
generateRegoParser
)
}
fun prop(name: String): String =
extra.properties[name] as? String
?: error("Property `$name` is not defined in gradle.properties")
val SourceSet.kotlin: SourceDirectorySet
get() =
(this as HasConvention)
.convention
.getPlugin(KotlinSourceSet::class.java)
.kotlin
fun SourceSet.kotlin(action: SourceDirectorySet.() -> Unit) =
kotlin.action()