[New software model] Groovy Support in the Component Model


(Rowan Lonsdale) #1


I was trying to compile a java and groovy project using the component model, something like:

model {
    components {
        myLib(JvmLibrarySpec) {
            sources {

It looks like a Groovy source component hasn’t been created yet, so this doesn’t work.

I then tried to write a small plugin that added Groovy support myself, following the UserGuide instructions on extending the software model. Here’s my build file so far:

interface GroovySourceSetSpec extends LanguageSourceSet {}
class DefaultGroovySourceSetSpec extends BaseLanguageSourceSet implements GroovySourceSetSpec {}

class GroovyRules extends RuleSource {
	void registerGroovyLanguage(TypeBuilder<GroovySourceSetSpec> builder) {
	void generateCompileGroovyTasks(ModelMap<Task> tasks, final JvmBinarySpec binary) {
		binary.inputs.withType(GroovySourceSetSpec) { GroovySourceSetSpec groovySource ->
			def taskName = binary.tasks.taskName("compile", groovySource.name)
			tasks.create(taskName, GroovyCompile) {
				destinationDir = binary.classesDir
				targetCompatibility = binary.targetPlatform.targetCompatibility
				sourceCompatibility = targetCompatibility

plugins {
	id "jvm-component"
	id "java-lang"

apply plugin: GroovyRules

model {
	components {
		myLib(JvmLibrarySpec) {
			sources {

Running gradle build on this produces the following output:

:compileExpJarGroovy FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':compileExpJarGroovy'.
> No value has been specified for property 'classpath'.
> No value has been specified for property 'groovyClasspath'.

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


Total time: 0.209 secs

And now I’m stuck - I can’t work out how to build a classpath from the parent component’s dependencies. Looking at the gradle source, the JavaLanguagePlugin uses a lot of internal classes to achieve this. I could copy this but in doing so I’d presumably be at risk of interface/contract changes.

Is there a recommended way to resolve DependencySpecs into classpaths/FileCollections from third-party plugins yet? If there isn’t, are there plans to create one? Or am I going about this totally the wrong way?

I’m using gradle 3.14.1


What's the status of Gradle's Software Model?
(Rowan Lonsdale) #2

…sorry, I meant 2.14.1, obviously

(Rowan Lonsdale) #3

I know I raised this topic 9 months ago. But I’m still waiting for a reply!

I’m starting to worry that the Software Component Model has been abandoned by Gradle, and I’ve raised a new topic asking about this here.

Can no-one help? Or at least confirm that what I’m trying to do is not yet possible?

(Daniel Lacasse) #4

Thank you for your patience @hWorblehat. You can find a response to this question on the new topic.