Gradle generateGrammarSource 任务不工作
Gradle generateGrammarSource task isn't working
我想使用 gradle generateGrammarSource
任务生成 antlr4 词法分析器。
g4 文件的路径是 src/main/antlr4/my/package/mygrammar.g4
我尝试使用我发现的一些示例,因此 build.gradle
具有以下代码:
buildscript {
ext.kotlin_version = '1.3.20'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
group 'my.package'
version '1.0-SNAPSHOT'
apply plugin: 'kotlin'
apply plugin: 'antlr'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile group: 'org.antlr', name: 'antlr4', version: '4.7.2'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
generateGrammarSource {
arguments += ['-package', 'my.package']
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
执行 generateGrammarSource
任务不会产生任何结果并给出以下输出:
:generateGrammarSource NO-SOURCE
BUILD SUCCESSFUL in 0s
我该如何解决?
您需要创建目录 src/main/antlr
并添加 Kotlin grammar files into there. most likely the my/package/
is the reason why it cannot find the grammar files; while this answers hints for, to add generated sources to the source-set. see The ANTLR Plugin.
我想使用 gradle generateGrammarSource
任务生成 antlr4 词法分析器。
g4 文件的路径是 src/main/antlr4/my/package/mygrammar.g4
我尝试使用我发现的一些示例,因此 build.gradle
具有以下代码:
buildscript {
ext.kotlin_version = '1.3.20'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
group 'my.package'
version '1.0-SNAPSHOT'
apply plugin: 'kotlin'
apply plugin: 'antlr'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile group: 'org.antlr', name: 'antlr4', version: '4.7.2'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
generateGrammarSource {
arguments += ['-package', 'my.package']
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
执行 generateGrammarSource
任务不会产生任何结果并给出以下输出:
:generateGrammarSource NO-SOURCE
BUILD SUCCESSFUL in 0s
我该如何解决?
您需要创建目录 src/main/antlr
并添加 Kotlin grammar files into there. most likely the my/package/
is the reason why it cannot find the grammar files; while this answers hints for, to add generated sources to the source-set. see The ANTLR Plugin.