Achieving simple root-project dependency


I recently got interested in the Gradle technology to build in DSL with XText. So far I have been successful in using XText and I’m in the process in splitting language and code generation in two separate root projects. Naturally, the code generation project (parent) depends on artifacts produced by the language project (child) and I don’t want my users to have to build two projects instead of one.

So far I have been unsuccessful at declaring the child project as a dependency of the parent project. I want it in such a way that when I change the source code in child and then compile parent, then child should update the jar artifact and parent should used the updated jar.

The over-simplified folder structure:

root/ settings.gradle build.gradle buildSrc/ src/ main/ groovy/ CodeGenerationTask.groovy folder1/ folder2/ settings.gradle build.gradle ProjectX/ build.gradle ProjectY/ build.gradle ProjectZ/ build.gradle

The “folder2” directory contains the root project for the DSL and injects shared configuration in ProjectX, ProjectY and ProjectZ. ProjectX produces a jar file. The “root” directory contains also a root project which depends on this jar at compilation time.

It looks like this:

root/settings.gradle = 'parent' include 'child' project(':child').projectDir = file("$settingsDir/folder1/folder2")


apply plugin: 'groovy' repositories { jcenter() } dependencies { // how to retrieve the xtextVersion variable from child project? compile 'org.eclipse.xtext:org.eclipse.xtext:???' // how to declare the jar dependency here? compile ??? } task GenerateCode(type: CodeGenerationTask) { ... }

root/folder1/folder2/settings.gradle = 'child' include 'ProjectX' include 'ProjectY' include 'ProjectZ'


buildscript { repositories { jcenter() } dependencies { classpath 'org.xtext:xtext-gradle-plugin:1.0.2' classpath 'org.xtext:xtext-idea-gradle-plugin:1.0.2' } } subprojects { ext.xtextVersion = '2.9.2' repositories { jcenter() } apply plugin: 'java' apply plugin: 'org.xtext.xtend' apply plugin: 'idea' }


dependencies { compile "org.eclipse.xtext:org.eclipse.xtext:${xtextVersion}" compile "org.eclipse.xtext:org.eclipse.xtext.xbase:${xtextVersion}" } task generateXtextLanguage (type: JavaExec) { ... }

When I issue “gradle projects” in “root” I don’t see ProjectX in the dependencies as I would expect:

Root project ‘parent’
— Project ‘:child’

, probably because the settings file is not written correctly. Can I achieve something like this? If yes, how should I modify my settings file? Moreover, assuming all this works at some point, how should I declare the jar dependency? How can I retrieve the xtext version variable?

Thanks for any help.

AFAIK you can only have one settings file per multi-project and it has to be in the root directory.

You can make one project depend on artifacts of another project by doing something like

  compile project(':ProjectX')

Gradle will then sort out order of project building for you.

P.S. It would help readability if you could format the source code in your posting within triple-backtick blocks.