[New software model] Groovy Support in the Component Model

Hi,

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

model {
    components {
        myLib(JvmLibrarySpec) {
            sources {
               groovy(GroovySourceSet)
            }
        }
    }
}

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 {
	
	@ComponentType
	void registerGroovyLanguage(TypeBuilder<GroovySourceSetSpec> builder) {
		builder.defaultImplementation(DefaultGroovySourceSetSpec)
	}
	
	@BinaryTasks
	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) {
				source(groovySource.source)
				destinationDir = binary.classesDir
				targetCompatibility = binary.targetPlatform.targetCompatibility
				sourceCompatibility = targetCompatibility
			}
		}
	}
	
}

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

apply plugin: GroovyRules

model {
	components {
		myLib(JvmLibrarySpec) {
			sources {
				groovy(GroovySourceSetSpec)
			}
		}
	}
}

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.

BUILD FAILED

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

Thanks

1 Like

…sorry, I meant 2.14.1, obviously

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?

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