{"record":{"id":"a2a294f2bfe14f31","repo":"gradle/gradle","slug":"unable-to-locate-grammar-exporting-specified-impor","errorCode":null,"errorMessage":"unable to locate grammar exporting specified import vocab [{}]","messagePattern":"unable to locate grammar exporting specified import vocab \\[(.+?)\\]","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"platforms/jvm/antlr/src/main/java/org/gradle/api/plugins/antlr/internal/antlr2/GenerationPlanBuilder.java","lineNumber":101,"sourceCode":"                        .getAssociatedGrammarMetadata().getGrammarFile();\n                if (superGrammarGrammarFileMetadata != null) {\n                    final GenerationPlan superGrammarGenerationPlan = locateOrBuildGenerationPlan(\n                            superGrammarGrammarFileMetadata);\n                    if (superGrammarGenerationPlan.isOutOfDate()) {\n                        generationPlan.markOutOfDate();\n                    } else if (superGrammarGenerationPlan.getSource().lastModified() > generatedParserFile\n                            .lastModified()) {\n                        generationPlan.markOutOfDate();\n                    }\n                }\n            }\n\n            // see if the grammar if out-of-date by way of its importVocab\n            if (isNotEmpty(grammarMetadata.getImportVocab())) {\n                final GrammarFileMetadata importVocabGrammarFileMetadata = metadataXRef.getGrammarFileByExportVocab(\n                        grammarMetadata.getImportVocab());\n                if (importVocabGrammarFileMetadata == null) {\n                    LOGGER.warn(\"unable to locate grammar exporting specified import vocab [\"\n                            + grammarMetadata.getImportVocab() + \"]\");\n                } else if (!importVocabGrammarFileMetadata.getFilePath().equals(grammarFileMetadata.getFilePath())) {\n                    final GenerationPlan importVocabGrammarGenerationPlan = locateOrBuildGenerationPlan(\n                            importVocabGrammarFileMetadata);\n                    generationPlan.setImportVocabTokenTypesDirectory(\n                            importVocabGrammarGenerationPlan.getGenerationDirectory());\n                    if (importVocabGrammarGenerationPlan.isOutOfDate()) {\n                        generationPlan.markOutOfDate();\n                    } else if (importVocabGrammarGenerationPlan.getSource().lastModified() > generatedParserFile\n                            .lastModified()) {\n                        generationPlan.markOutOfDate();\n                    }\n                }\n            }\n        }\n\n        generationPlans.put(generationPlan.getId(), generationPlan);\n        return generationPlan;","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/jvm/antlr/src/main/java/org/gradle/api/plugins/antlr/internal/antlr2/GenerationPlanBuilder.java#L83-L119","documentation":"For ANTLR 2 grammars, Gradle builds a GenerationPlan per grammar and cross-references each grammar's importVocab against the exportVocab declared by other grammar files in the same source set (metadataXRef.getGrammarFileByExportVocab). If no grammar exports the named vocabulary, the lookup returns null: Gradle warns and the importing grammar gets no importVocabTokenTypesDirectory, which usually surfaces as ANTLR generation errors (e.g. cannot find TokenTypes.txt) or mismatched token types.","triggerScenarios":"A grammar declares options { importVocab=MyTokens; } but no grammar passed to the same AntlrGenerateParserTask declares options { exportVocab=MyTokens; } - caused by a typo/case mismatch, a renamed vocab, or the exporting grammar living in a different source set or being excluded by the AntlrTask source filter.","commonSituations":"Typos or case mismatches between importVocab and exportVocab; multi-grammar token-sharing setups where one grammar file was moved, renamed, or excluded; migrating legacy AntlrPlugin configurations between projects or source sets.","solutions":["Diff every importVocab=X against an exportVocab=X in the same antlr source set - names are case-sensitive","Make sure the exporting grammar is actually included in the AntlrTask's sources (check includes/excludes and source set layout)","Run ./gradlew clean generateGrammarSource so all generation plans are rebuilt once the link resolves","If the vocabulary was renamed intentionally, update both sides: exportVocab in the token grammar and importVocab in every importing parser grammar"],"exampleFix":"// before: vocab names do not match -> warning + broken generation\n// MyTokensParser.g: options { importVocab=MyToken; }   // typo\n// MyTokens.g:       options { exportVocab=MyTokens; }\n\n// after: names match exactly (case-sensitive)\n// MyTokensParser.g: options { importVocab=MyTokens; }\n// MyTokens.g:       options { exportVocab=MyTokens; }","handlingStrategy":"validation","validationCode":"// build.gradle: fail fast if an importVocab has no matching exportVocab\ntasks.register('validateGrammars') {\n    doLast {\n        def grammars = fileTree('src/main/antlr').matching { include '**/*.g' }\n        def exports = grammars.files.collect { f ->\n            (f.text =~ /exportVocab\\s*=\\s*(\\w+)/).collect { it[1] }\n        }.flatten().toSet()\n        grammars.each { f ->\n            (f.text =~ /importVocab\\s*=\\s*(\\w+)/).each { m ->\n                if (!exports.contains(m[1])) {\n                    throw new GradleException(\"${f.name}: importVocab '${m[1]}' has no matching exportVocab\")\n                }\n            }\n        }\n    }\n}\ntasks.named('generateGrammarSource') { dependsOn 'validateGrammars' }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep token-sharing grammar pairs (exporter + importer) in the same antlr source set","Name the exportVocab after the token grammar file; never rename one side without the other","Run a CI validation that every importVocab resolves to an exportVocab before generateGrammarSource"],"tags":["gradle","antlr","antlr2","code-generation","grammar","token-vocabulary"],"backgroundTag":"antlr-import-vocab-unresolved","analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}