Xtext:无法解析对 JvmType MyGeneratorModule 的引用

Xtext: Couldn't resolve reference to JvmType MyGeneratorModule

我正在使用实体和状态机示例为多个 dsl 复制示例 Xtext Web 项目的结构。我正在使用 Gradle 作为我的构建系统。我的两个语法项目中都有 class MyGeneratorModule。在我的工作流程中,我这样引用它:
configuration = MyGeneratorModule {...}
我可以 运行 每个项目的工作流程都很好,但是当我尝试从 Web 项目执行 jettyRun 时,我收到此错误:

Task :com.selinc.logic.program:generateXtextLanguage FAILED
0    [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - [XtextLinkingDiagnostic: null:17 Couldn't resolve reference to JvmType 'MyGeneratorModule'.

我是否在工作流程或 gradle 构建中遗漏了什么?这是我的语言 build.gradle 文件和工作流程的更完整示例:

mwe2:

component = XtextGenerator {
        configuration = MyGeneratorModule { // <- This is what is not resolving
            project = StandardProjectConfig {
                baseName = baseName
                rootPath = rootPath
                runtimeTest = {
                    enabled = true
                }
                web = {
                    enabled = true
                    root = "../myWebProject"
                    src = "../myWebProject/src/main/java"
                    srcGen = "../myWebProject/src/main/xtext-gen"
                    assets = "../myWebProject/src/main/webapp"
                }
                mavenLayout = true
            }
            code = {
                encoding = "UTF-8"
                lineDelimiter = "\r\n"
                fileHeader = "/*\n * generated by Xtext ${version}\n */"
            }
        }
        cleaner = {
            exclude = "MyOtherLanguageWebModule.java"
        }
        language = StandardLanguage {
            name = "MyLang"
            fileExtensions = "lang"
            serializer = {
                generateStub = false
            }
            webSupport = {
                generateHtmlExample = true
                framework = "CODEMIRROR"
                generateJsHighlighting = false
                generateServlet = false
                generateWebXml=true 
            }
            junitSupport = {
                junitVersion = "5"
            }
        }
    }

build.gradle:

    dependencies {
    testCompile "org.junit.jupiter:junit-jupiter-api:5.1.0"
    testRuntime "org.junit.jupiter:junit-jupiter-engine:5.1.0"
    testCompile "org.eclipse.xtext:org.eclipse.xtext.testing:${xtextVersion}"

    compile project(':myOtherLang')
    compile project(':myXCoreModel')
    compile project(":util")

    compile group: 'org.eclipse.xtext', name: 'org.eclipse.xtext.ecore', version: '2.15.0'
    compile "org.eclipse.xtext:org.eclipse.xtext.xbase:${xtextVersion}"
}
sourceSets {
    mwe2 {}
}
configurations {
    mwe2 {
        extendsFrom compile
    }
    mwe2Compile.extendsFrom mainCompile
    mwe2Runtime.extendsFrom mainRuntime
}
sourceSets.mwe2.java.srcDir 'generator'

dependencies {
    mwe2Compile "org.eclipse.emf:org.eclipse.emf.mwe2.launch:2.9.1.201705291010"
    mwe2Compile "org.eclipse.xtext:org.eclipse.xtext.common.types:${xtextVersion}"
    mwe2Compile "org.eclipse.xtext:org.eclipse.xtext.xtext.generator:${xtextVersion}"
    mwe2Compile "org.eclipse.xtext:xtext-antlr-generator:[2.1.1, 3)"

    //added for xcore support
    mwe2Compile 'org.eclipse.emf:org.eclipse.emf.ecore.xcore:1.3.1'
    mwe2Compile 'org.eclipse.emf:org.eclipse.emf.codegen.ecore.xtext:+'
}

task generateXtextLanguage(type: JavaExec) {
    main = 'org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher'
    classpath = project.sourceSets.mwe2.runtimeClasspath
    inputs.file "path/GenerateMyLang.mwe2"
    inputs.file "path/MyLang.xtext"
    outputs.dir "src-gen"
    args += "path/GenerateMyLang.mwe2"
    args += "-p"
    args += "rootPath=/${projectDir}/.."
}

test {
    useJUnitPlatform()
}
generateXtext.dependsOn(generateXtextLanguage)
clean.dependsOn(cleanGenerateXtextLanguage)
eclipse.classpath.plusConfigurations += [configurations.mwe2]

我怀疑这是否有效。您从中复制的代码不会生成 xtext 语言 您应该将自定义模块移至单独的 gradle 项目,从而单独编译它。或者你可以尝试 gradle buildSrc/separate 源文件夹代码

(我不确定这是否适用于这个用例)

dependencies {
    compile "org.eclipse.xtext:org.eclipse.xtext:${xtextVersion}"
    compile "org.eclipse.xtext:org.eclipse.xtext.xbase:${xtextVersion}"
}
sourceSets {
    mwe2 {}
}
configurations {
    mwe2 {
        extendsFrom compile
    }
    mwe2Compile.extendsFrom mainCompile
    mwe2Runtime.extendsFrom mainRuntime
}
sourceSets.mwe2.java.srcDir 'generator'

dependencies {
    mwe2Compile "org.eclipse.emf:org.eclipse.emf.mwe2.launch:2.9.1.201705291010"
    mwe2Compile "org.eclipse.xtext:org.eclipse.xtext.common.types:${xtextVersion}"
    mwe2Compile "org.eclipse.xtext:org.eclipse.xtext.xtext.generator:${xtextVersion}"
    mwe2Compile "org.eclipse.xtext:xtext-antlr-generator:[2.1.1, 3)"
}

task generateXtextLanguage(type: JavaExec) {
    main = 'org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher'
    classpath = project.sourceSets.mwe2.runtimeClasspath
    inputs.file "src/org/xtext/example/mydsl/GenerateMyDsl.mwe2"
    inputs.file "src/org/xtext/example/mydsl/MyDsl.xtext"
    outputs.dir "src-gen"
    args += "src/org/xtext/example/mydsl/GenerateMyDsl.mwe2"
    args += "-p"
    args += "rootPath=/${projectDir}/.."
}

generateXtext.dependsOn(generateXtextLanguage)
clean.dependsOn(cleanGenerateXtextLanguage)
eclipse.classpath.plusConfigurations += [configurations.mwe2]