I’m trying to break ground on a plugin that registers a new type of source set. For as much reading as I have done, I can’t quite find a definitive source of truth on how my new source set ought to be registered.
I know so far as to extend each top-level source set, so for example:
sourceSets {
main { // or all {}
kotlin { ... }
abc { ... }
}
}
For the abc
source sets, I add their sourceDirectories
to allSource
; something like:
sourceSets {
all { topLevelSourceSet ->
abc { abcSourceSet ->
// sourceDirectories will later resolve to 'src/${abcSourceSet.name}/abc'
topLevelSourceSet.allSource.srcDirs(abcSourceSet.abc.sourceDirectories)
}
}
}
I imagine this should be enough for IDEs to recognize src/main/abc
or src/test/abc
as a source root. But after some digging, IntelliJ requires registering the source roots:
project.plugins.withId("idea") { plugin ->
val idea = plugin as? IdeaPlugin ?: return@withId // just to be sure
abcSourceSets.all { abcSourceSet ->
idea.model.module.apply {
// I've tried many forms of this, +=, project.files, etc
sourceDirs.addAll(abcSourceSets.abc.sourceDirectories)
}
}
}
But, as it turns out, idea
is only applied after the project is evaluated. I could require that idea
be applied before my plugin, but even the kotlin
plugin doesn’t require this. I still haven’t figured out how to invoke the correct configuration. I’m stuck–please help!