Okumo
Okumo

Reputation: 169

Gradle generateGrammarSource task isn't working

I want to generate antlr4 lexer using gradle generateGrammarSource task.
Path to g4 file is src/main/antlr4/my/package/mygrammar.g4
I tried to use some examples I found so build.gradle has the following code:

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"
}

Executing generateGrammarSource task generates nothing and gives the following output:

:generateGrammarSource NO-SOURCE

BUILD SUCCESSFUL in 0s

How can I fix it?

Upvotes: 1

Views: 3085

Answers (1)

Martin Zeitler
Martin Zeitler

Reputation: 76569

you need to create directory src/main/antlr and add 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.

Upvotes: 1

Related Questions