mpl/build.gradle
2026-07-09 18:38:37 -04:00

64 lines
No EOL
1.7 KiB
Groovy

plugins {
id 'java'
id 'antlr'
}
group = 'com.mpl'
version = '0.1-alpha'
repositories {
mavenCentral()
}
dependencies {
antlr 'org.antlr:antlr4:4.13.1'
implementation 'org.antlr:antlr4-runtime:4.13.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.hamcrest:hamcrest:2.2'
}
generateGrammarSource {
maxHeapSize = "64m"
// -Werror: any ANTLR warning (e.g. 184, token shadowing) fails the build
arguments += ["-visitor", "-listener", "-Werror", "-package", "com.mpl.parser"]
outputDirectory = file("${project.buildDir}/generated-src/antlr/main/com/mpl/parser")
}
compileJava.dependsOn generateGrammarSource
sourceSets {
main {
antlr {
// The Gradle ANTLR plugin defaults to src/main/antlr; the grammar
// lives in src/main/antlr4 (Maven layout).
srcDirs = ['src/main/antlr4']
}
java {
srcDirs += "${project.buildDir}/generated-src/antlr/main"
}
}
}
test {
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
}
// ParseExamples lives in the test source set, so the task needs the test
// runtime classpath (with main.runtimeClasspath the class was never found).
task parseExamples(type: JavaExec, dependsOn: testClasses) {
mainClass = 'com.mpl.test.ParseExamples'
classpath = sourceSets.test.runtimeClasspath
args = ['examples']
}
// Grammar-check CLI (see ParseCheck.java): file paths or '-' for stdin via
// --args passthrough, e.g. ./gradlew -q parseCheck --args='examples/01_hello_world.mpl'
task parseCheck(type: JavaExec, dependsOn: classes) {
mainClass = 'com.mpl.tools.ParseCheck'
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
}