1

I'm trying to create a first project using xText and xTend building with gradle.

I created the grammar following the guidance in the xText documentation and also created the xtend generators.

In eclipse the code generates to src-gen folder as expected.

When I created the gradle script, also following the http://xtext.github.io/xtext-gradle-plugin/xtext-builder.html to build my code instead of generating the code in 'src-gen' folder it generates in 'build' folder.

Is there any way to change this folder from build to src-gen in the gradle? I tried a lot of things and I got always errors.

Complete code of grade script:

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'
      }
    }
}
Hugo Dias
  • 341
  • 3
  • 13

1 Answers1

2

you can configure that in the source set

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

e.g.

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'

}

or for the xtxt builder plugin

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')
                }
        }
    }
  }
Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32
  • That was one of my options but I have this error: A problem occurred evaluating script. > Could not find method xtendOutputDir() for arguments [src-gen] on [src/main/xtext] of type org.xtext.gradle.tasks.internal.DefaultXtextSourceDirectorySet. – Hugo Dias Mar 15 '18 at 12:38
  • How does your complete Gradle file look like. Did you apply the plugin – Christian Dietrich Mar 15 '18 at 12:52
  • I updated the original message to include the full content of the gradle file. In the parent project I added the dependency to my grammar jar, that I published into my local ivy repository. – Hugo Dias Mar 15 '18 at 14:14
  • so the question is about xtext and not xtend? – Christian Dietrich Mar 15 '18 at 17:45
  • For me is hard to know the border line because the grammar is written in xtext but the generator is in Xtend. Currently what I can't do is, when I compile with Gradle the generated sources are created in the build folder instead of src-gen. – Hugo Dias Mar 15 '18 at 18:54
  • Is there also an option specifically targeting xcore models? My generated code always ends up in `build/main/xcore` regardless. – Mad Matts Mar 16 '18 at 13:19
  • sorry i dont know that. – Christian Dietrich Mar 16 '18 at 14:00
  • @Christian Thanks for your help. I was able to do that using: sourceSets { main { srcDir 'src/main/xtext' output { dir(xtext.languages.taenum.generator.outlet, 'src-gen') } } } – Hugo Dias May 10 '18 at 13:22