1

I have written a DSL with Xtext 2.12 and my Xtend 2.12 code generator produces Java 8 code from it. I am using Eclipse Oxygen.3a. I started by creating an Xtext project as an Eclipse plug-in and all works fine, but I would like to have everything built by Gradle now. For that purpose, I have added the Gradle nature to my Xtext project and launched 'gradle init' to generate the build.gradle and settings.gradle files. I have discovered the existence of Xtext Gradle Plugins (Xtext Builder and Xtend Compiler), and used the documentation of these plugins to write the build.gradle script content, but I did not understand everything and, not surprisingly, my builder does not work. Could you help me please to set this builder up correctly?

plugins {
  id 'org.xtext.builder' version '2.0.3'
  id "org.xtext.xtend" version "2.0.3"
}

apply plugin: 'java'
apply plugin: 'org.xtext.xtend'
apply plugin: 'eclipse'

sourceSets {
  main.java.srcDirs = ['src','xtend-gen']
  main.xtendOutputDir = 'xtend-gen'
}

repositories {
  mavenCentral()
  jcenter()
}

dependencies {
  compile group: 'org.eclipse.xtend', name: 'org.eclipse.xtend.lib', version: '2.16.0'
  compile group: 'org.eclipse.xtext', name: 'org.eclipse.xtext', version: '2.16.0'
  compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.codegen.ecore', version: '2.15.0'
  compile group: 'org.eclipse.xtext', name: 'org.eclipse.xtext.xtext.generator', version: '2.16.0'
  testCompile group: 'org.eclipse.xtext', name: 'org.eclipse.xtext.xbase.testing', version: '2.16.0'
}

xtext {
  languages {
    mapy {
      setup = 'com.mchp.mapy.MapyStandaloneSetup'
      generator.outlet.producesJava = true
    }
  }
  sourceSets {
    main {
      srcDirs 'src','xtend-gen'
      output {
        dir(xtext.languages.mapy.generator.outlet, 'src-gen')
      }
    }
  }
}

xtend {

}
  1. Where should the sourceSets block be located (inside or outside the xtext block)?
  2. Is the xtext block content correct?
  3. What should I write into the xtend block? Should it even be declared?
  4. What is the Gradle task to be run to start the MWE2 launcher and then the code generator?

Following is a snapshot of my Eclipse project organization. Thanks in advance for your time!

enter image description here

Georgie
  • 77
  • 6
  • since there are zero ui artifacts available in maven central or jcenter i dont see how this should would. for non ui parts have a look what the xtext wizard creates if you select gradle as buildsystem – Christian Dietrich Feb 25 '19 at 22:52
  • Thanks for your reply Christian. Unfortunately, the Xtext Project wizard does not allow building Eclipse plug-ins with Gradle. That's the reason why I was exploring an other path. – Georgie Feb 26 '19 at 06:41
  • There is nothing that does. In Xtext source code we basically package the manifest into the jar. See github.com/eclipse/Xtext-core . There is no validation etc – Christian Dietrich Feb 26 '19 at 08:32
  • you also can build it with help of maven. Did you try to use maven to build it ? – Jahongir Sabirov Apr 03 '19 at 18:05
  • @Jahongir No, I didn't and I don't want to learn it for a single project. Thanks for your answer. – Georgie Apr 04 '19 at 05:42

1 Answers1

0

It is also possible to build the Xtext plugins using Eclipse PDE. I created a dedicated Eclipse deployment to keep the size down (minimal then install the PDE, JDT and Xtext projects) which is published to an artifact repository. It's then just a matter of writing Gradle tasks (or a plugin) to pull down the Eclipse, extract it to the build directory, copy in the Xtext Eclipse projects (use the Xtext Gradle plugin to build the DSL before copying) and finally call the Ant PDE task(s) using the Java command and the AntRunner inside the Eclipse. The output should be a basic update site from which you can either install the plugins from locally or publish to the Artifact repository to share.

A good understanding of Eclipse PDE build process is required. I found most of what I needed in the Eclipse help (https://help.eclipse.org/2020-06/index.jsp) under section "Plug-in Development Environment Guide > Tasks > PDE Build"

I have encountered some issues during Xtext version upgrades with various dependency conflicts and Eclipse bugs. These can usually be resolved with the help of the Xtext dev team and then forcing certain dependencies in Gradle.

Unfortunately I can't share any of the build as it's a proprietary code, but I hope the explanation above is enough for anyone who needs to automate the process. It's certainly not a simple thing to set up though.

Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32
Ross Perston
  • 51
  • 1
  • 1