【问题标题】:Define the generator code location using gradle to build xtext and xtend使用 gradle 定义生成器代码位置来构建 xtext 和 xtend
【发布时间】:2018-03-16 16:04:39
【问题描述】:

我正在尝试使用 xText 和带有 gradle 的 xTend 构建第一个项目。

我按照 xText 文档中的指导创建了语法,还创建了 xtend 生成器。

在 Eclipse 中,代码按预期生成到 src-gen 文件夹。

当我创建 gradle 脚本时,也遵循 http://xtext.github.io/xtext-gradle-plugin/xtext-builder.html 来构建我的代码,而不是在它在 'build' 文件夹中生成的 'src-gen' 文件夹中生成代码。

有什么方法可以在 gradle 中将此文件夹从 build 更改为 src-gen 吗?我尝试了很多东西,但总是出错。

成绩脚本的完整代码:

apply plugin: 'org.xtext.builder'

dependencies {
    xtextLanguages 'com.example.mylang:mylang:1.0.0-SNAPSHOT'
}

xtext {
    languages {
      mylang{
        setup = 'com.example.MyLangStandaloneSetup'
        generator.outlet.producesJava = true
      }
    }
    sourceSets {
      main {
        srcDir 'src/main/xtext'
    xtendOutputDir 'src-gen'
      }
    }
}

【问题讨论】:

    标签: gradle xtext xtend


    【解决方案1】:

    您可以在源集中配置它

    sourceSets {
       main.xtendOutputDir = 'xtend-gen'
    }
    

    例如

    plugins {
      id "org.xtext.xtend" version "1.0.21"
    }
    
    apply plugin: 'java'
    apply plugin: 'org.xtext.xtend'
    
    sourceSets {
      main.java.srcDirs = ['src','xtend-gen']
      main.xtendOutputDir = 'xtend-gen'
    }
    
    repositories {
        jcenter()
    }
    
    dependencies {
        // This dependency is exported to consumers, that is to say found on their compile classpath.
        compile 'org.eclipse.xtext:org.eclipse.xtext.xbase.lib:2.13.0'
    
    }
    

    或用于 xtxt 构建器插件

    buildscript {
        repositories {
            mavenLocal()
                jcenter()
        }
        dependencies {
            classpath 'org.xtext:xtext-gradle-plugin:1.0.21'
        }
    }
    plugins {
        id "org.xtext.builder" version "1.0.21"
    }
    
    repositories {
        mavenLocal()
        jcenter()
    }
    
    dependencies {
        xtextLanguages 'org.xtext.example.mydslfoo:org.xtext.example.mydslfoo:1.0.0-SNAPSHOT'
    }
    
    xtext {
        version '2.13.0'
        languages {
            mydslfoo {
                setup = 'org.xtext.example.mydslfoo.MyDslFooStandaloneSetup'
                generator {
                    outlets {
                        HEROES {              
                        }
                        }
                }
            }
        }
        sourceSets {
            main {
                srcDir 'src'
                output {
                    dir(xtext.languages.mydslfoo.generator.outlet, 'src-gen')
                    }
            }
        }
      }
    

    【讨论】:

    • 这是我的选择之一,但我有这个错误:评估脚本时出现问题。 > 在 org.xtext.gradle.tasks.internal.DefaultXtextSourceDirectorySet 类型的 [src/main/xtext] 上找不到参数 [src-gen] 的方法 xtendOutputDir()。
    • 你的完整 Gradle 文件是什么样子的。你应用插件了吗
    • 我更新了原始消息以包含 gradle 文件的全部内容。在父项目中,我将依赖项添加到我的语法 jar 中,并将其发布到本地 ivy 存储库中。
    • 所以问题是关于 xtext 而不是 xtend?
    • 对我来说很难知道边界线,因为语法是用 xtext 编写的,但生成器是用 Xtend 编写的。目前我不能做的是,当我使用 Gradle 编译时,生成的源代码是在 build 文件夹而不是 src-gen 中创建的。
    猜你喜欢
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    相关资源
    最近更新 更多