Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xcore/xtext-gradle-plugin generates raw type references when invoked from Gradle
Xcore/xtext-gradle-plugin generates raw type references when invoked from Gradle [message #1716728] Mon, 07 December 2015 19:00 Go to next message
Dominik Klumpp is currently offline Dominik KlumppFriend
Messages: 4
Registered: December 2015
Junior Member
The problem:

I have a Xtext project with a Xcore model. In Eclipse, it works fine: the model is generated without problems.

The Xcore model contains among other things this fragment:
class RuleSystem {
  contains Rule[] rules
}
class Rule {
}


I'm attempting to automate the generation using gradle and the xtext gradle plugin. I based my build.gradle on the example project at https://github.com/ghillairet/xcore-gradle-example. The build executes successfully, but the generated code differs in that it's missing type parameters:

Where Eclipse would generate
EList<Rule> getRules();

the gradle build generates:
EList getRules();
etc. (for every such instance). This of course leads to a lot of warnings and some type errors.

The build.gradle file I'm using:
plugins {
  id "org.xtext.xtext" version "0.3.26" // used to build Xcore model
  id "org.xtend.xtend" version "0.4.14"
  id "java"
  id "eclipse"
}

group 'rapanui'
version '0.1.0-alpha.1'

sourceCompatibility = 1.8
targetCompatibility = 1.8

jar.manifest {
  from 'META-INF/MANIFEST.MF'
}

repositories {
  mavenCentral()
}

/* * * * * Configuration for Xcore * * * * *
Adapted from https://github.com/ghillairet/xcore-gradle-example */
xtext {
  version = '2.9+'
  encoding = 'UTF-8'

  sources {
    srcDir 'src'
  }

  languages {
    ecore {
      setup = 'org.eclipse.xtext.ecore.EcoreSupport'
    }
    codegen {
      setup = 'org.eclipse.emf.codegen.ecore.xtext.GenModelSupport'
    }
    xcore {
      setup = 'org.eclipse.emf.ecore.xcore.XcoreStandaloneSetup'
      consumesJava = true
      output {
        dir = 'xcore-gen'
        producesJavaFor sourceSets.main
      }
    }
  }
}

/* Java source code. 'xcore-gen' is added by the Xcore config above. */
sourceSets {
  main {
    java {
      srcDir 'src'
      srcDir 'src-gen'
    }
    xtendOutputDir = 'xtend-gen'
  }
}

configurations {
  xtext.extendsFrom compile // for workflow execution
  xtextTooling.extendsFrom xcore // alias xtextTooling to xcore to prevent confusion
}

dependencies {
  compile 'org.eclipse.xtext:org.eclipse.xtext.xtext:2.9+'
  compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.9.+'
  compile 'org.eclipse.emf:org.eclipse.emf.ecore.xcore.lib:1.1.100'

  xtext files('src')
  xtext 'org.eclipse.emf:org.eclipse.emf.ecore.xcore:1.3.1'
  xtext 'org.ow2.asm:asm:5.0+'
  xtext 'org.eclipse.emf:org.eclipse.emf.codegen.ecore.xtext:1.2.0'
  xtext 'org.eclipse.xtext:org.eclipse.xtext.xbase:2.9+'

  xcore 'org.eclipse.text:org.eclipse.text:3.5.101'
  xcore 'org.eclipse.core:org.eclipse.core.resources:3.7.100'
  xcore 'org.eclipse.xtext:org.eclipse.xtext.ecore:2.9.0'
  xcore 'org.eclipse.emf:org.eclipse.emf.codegen.ecore.xtext:1.2.0'
  xcore 'org.eclipse.emf:org.eclipse.emf.common:2.11+'
  xcore 'org.eclipse.emf:org.eclipse.emf.ecore.xmi:2.11+'
  xcore 'org.eclipse.emf:org.eclipse.emf.ecore.xcore:1.3.1'
  xcore 'org.eclipse.emf:org.eclipse.emf.ecore.xcore.lib:1.1.100'
  xcore 'org.eclipse.emf:org.eclipse.emf.codegen:2.10+'
  xcore 'org.eclipse.emf:org.eclipse.emf.codegen.ecore:2.11+'
}

/* delete generated code */
clean {
  delete 'xcore-gen'
  delete 'xtend-gen'
  delete 'src-gen'
}

/* generate Xcore model using Xtext plugin */
task(generateModel).dependsOn xtextGenerate

/* language artifact generation by workflow execution */
task(generateLang, type: JavaExec) {
  inputs.files "src/rapanui/dsl/GenerateDsl.mwe2", "src/rapanui/dsl/Dsl.xtext"
  outputs.dir "src-gen"

  dependsOn generateModel // model needs to be generated first
  classpath configurations.xtext
  main = "org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher"
  args "src/rapanui/dsl/GenerateDsl.mwe2"
}

/* Language is generated before Xtend is compiled.
Since Xtend is integrated into the build task, this also integrates
generateLang and thus generateModel into the build task. */
compileXtend.dependsOn generateLang

eclipse.project {
  natures 'org.eclipse.buildship.core.gradleprojectnature'
  natures 'org.eclipse.pde.PluginNature'
  natures 'org.eclipse.xtext.ui.shared.xtextNature'

  buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
  buildCommand 'org.eclipse.xtext.ui.shared.xtextBuilder'
  buildCommand 'org.eclipse.pde.SchemaBuilder'
  buildCommand 'org.eclipse.pde.ManifestBuilder'
}


Any ideas on how to fix this? Am I missing any dependencies? Or doing something wrong?

Any help would be greatly appreciated.

[Updated on: Tue, 08 December 2015 15:32]

Report message to a moderator

Re: Xcore/xtext-gradle-plugin generates raw type references when invoked from Gradle [message #1716785 is a reply to message #1716728] Tue, 08 December 2015 08:33 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Hi Dominik,

your build file looks good and the xtext-gradle-plugin is just a thin wrapper around the Xtext standalone builder. It's hard to tell why Xcore would behave differently in this scenario.

Can you come up with a small example project that reproduces this problem?

Cheers,
Stefan
Re: Xcore/xtext-gradle-plugin generates raw type references when invoked from Gradle [message #1716810 is a reply to message #1716785] Tue, 08 December 2015 11:14 Go to previous messageGo to next message
Dominik Klumpp is currently offline Dominik KlumppFriend
Messages: 4
Registered: December 2015
Junior Member
No problem, here it is: https://github.com/maul-esel/xcore-gradle-example - just clone and run
gradle clean build

The file xcore-gen/xcore/test/MyModel.java contains
EList getElements();
.

[Updated on: Tue, 08 December 2015 11:16]

Report message to a moderator

Re: Xcore/xtext-gradle-plugin generates raw type references when invoked from Gradle [message #1716818 is a reply to message #1716810] Tue, 08 December 2015 11:50 Go to previous messageGo to next message
Dominik Klumpp is currently offline Dominik KlumppFriend
Messages: 4
Registered: December 2015
Junior Member
I just looked at the build output again, and found that hidden between the output of the generated java files there are a lot of lines like this:
A problem was detected while parsing a Java file
	Line 151: Syntax error, parameterized types are only available if source level is 1.5 or greater
	Line 151: Syntax error, parameterized types are only available if source level is 1.5 or greater
	Line 153: Syntax error, parameterized types are only available if source level is 1.5 or greater
	Line 155: Syntax error, parameterized types are only available if source level is 1.5 or greater
	Line 157: Syntax error, parameterized types are only available if source level is 1.5 or greater

Any idea what causes this? I did set sourceCompatibility to 1.8 in the gradle file.

[Updated on: Tue, 08 December 2015 12:26]

Report message to a moderator

Re: Xcore/xtext-gradle-plugin generates raw type references when invoked from Gradle [message #1716840 is a reply to message #1716818] Tue, 08 December 2015 13:53 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

I guess XCore calls the JDT formatter to pretty-print the generated Java code. Apparently it doesn't use the Java version provided by Xtext, but some other (default?) version. Maybe you can deactivate it using a GenModel property:

@GenModel(codeFormatting = false)
Re: Xcore/xtext-gradle-plugin generates raw type references when invoked from Gradle [message #1716855 is a reply to message #1716840] Tue, 08 December 2015 15:32 Go to previous message
Dominik Klumpp is currently offline Dominik KlumppFriend
Messages: 4
Registered: December 2015
Junior Member
That in itself didn't quite do the trick, but modifying the GenModel annotation was definitely the right idea: I simply had to specify
@GenModel(complianceLevel="8.0")
explicitly in the xcore file. Now it works fine!

Thanks a lot for your support!

[Updated on: Tue, 08 December 2015 15:32]

Report message to a moderator

Previous Topic:Couldn't resolve reference to JvmType 'parser.antlr.ex.rt.AntlrGeneratorFragment'
Next Topic:update specific outline node by changing its background
Goto Forum:
  


Current Time: Wed Apr 24 20:58:53 GMT 2024

Powered by FUDForum. Page generated in 0.03742 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top