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