Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Gradle and GeneratorFragment(How to integrate a standalone setup in your gradle build?)
Gradle and GeneratorFragment [message #1791398] Thu, 28 June 2018 17:56 Go to next message
Tobias Blaufuß is currently offline Tobias BlaufußFriend
Messages: 4
Registered: June 2018
Junior Member
Hello,

i've created a xtext project (my.example.domain.mydsl) with gradle as preferred build system and a plain source layout. My project layout looks like this:

my.example.domain.mydsl.parent (Main gradle project)
my.example.domain.mydsl.target
my.example.domain.mydsl (gradle subproject)
my.example.domain.mydsl.tests (gradle subproject)
my.example.domain.mydsl.ide (gradle subproject)
my.example.domain.mydsl.ui


I added the following GeneratorFragment to my .mwe2 configuration:

fragment = generator.GeneratorFragment2 {
				generateJavaMain = true
}


This will generate a Main.java file in the package my.example.domain.mydsl.generator of the gradle subproject my.example.domain.mydsl

When i execute the generated Main-class inside eclipse it runs the generator on my provided resource files perfectly fine, but i want to execute this java application via gradle and without eclipse (AFTER the generateXtextLanguage task)

My gradle build inside the gradle subproject my.example.domain.mydsl looks like this:
dependencies {
	compile "org.eclipse.xtext:org.eclipse.xtext:${xtextVersion}"
	compile "org.eclipse.xtext:org.eclipse.xtext.xbase:${xtextVersion}"
}
configurations {
	mwe2 {
		extendsFrom compile
	}
}

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

task generateXtextLanguage(type: JavaExec) {
	main = 'org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher'
	classpath = configurations.mwe2
	inputs.file "src/my/example/domain/mydsl/GenerateGlossaryModel.mwe2"
	inputs.file "src/my/example/domain/mydsl/Mydsl.xtext"
	outputs.dir "src-gen"
	args += "src/my/example/domain/mydsl/GenerateMydsl.mwe2"
	args += "-p"
	args += "rootPath=/${projectDir}/.."
}

task generateXtextModels(type: JavaExec) {
	main = 'my.example.domain.mydsl.generator.Main'
       // Provide some parameters, arguments, etc.
       // ...
}

generateXtext.dependsOn(generateXtextLanguage)
generateXtext.dependsOn(generateXtextModels)
generateXtextModels.dependsOn(generateXtextLanguage)
clean.dependsOn(cleanGenerateXtextLanguage)
eclipse.classpath.plusConfigurations += [configurations.mwe2]
//this is an eclipse plugin project
eclipseClasspath.enabled=false
cleanEclipseClasspath.enabled=false


It's basically the automatically generated gradle build with an extra task "generateXtextModels" and 2 "dependsOn" statements.

When i execute "gradle build" i get the following error:
> Task :my.example.domain.mydsl:generateXtextLanguage UP-TO-DATE

> Task :my.example.domain.mydsl:generateXtextModels FAILED
Error: Could not find or load main class my.example.domain.mydsl.generator.Main

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':my.example.domain.mydsl:generateXtextModels'.
> Process 'command '/usr/lib/jvm/java-8-openjdk/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at gradle

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See docs

BUILD FAILED in 0s
2 actionable tasks: 1 executed, 1 up-to-date


I really don't know where to go from here. I've tried some things with classpaths, sourceSets and plugins, but I'm not making any progress here. Has anyone an idea how to call this generator class via gradle?


Thank you in advance
Re: Gradle and GeneratorFragment [message #1791574 is a reply to message #1791398] Mon, 02 July 2018 15:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12230
Registered: July 2009
Senior Member
maybe you should move the fragment to a separate subproject or use a buildSrc https://docs.gradle.org/current/userguide/organizing_gradle_projects.html project to compile the fragment.

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Gradle and GeneratorFragment [message #1791628 is a reply to message #1791574] Tue, 03 July 2018 07:50 Go to previous message
Tobias Blaufuß is currently offline Tobias BlaufußFriend
Messages: 4
Registered: June 2018
Junior Member
I've solved the problem by creating an executable jar file instead of executing it directly
Previous Topic:Creating multiple embedded editors with (slightly) specific content assist
Next Topic:Xtext Gradle Plugin and Xtext Builder
Goto Forum:
  


Current Time: Thu Sep 20 13:15:44 GMT 2018

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

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

Back to the top