Firstly to clarify the scope, this question is about the existing (old) model of doing language plugins. If someone wants to augment an answer with how it will work in the model, that is fine, but I would like to see if the problem firstly can be solved with the old way.
The problem: Let’s say I am adding a new source set to an existing JVM language as part of a plugin i.e. for integration tests I might have code roughly the equivalent of below:
project.sourceSets {
integrationTest {
java.srcDir project.file( "src/integrationTest/java" )
resources.srcDir project.file( "src/integrationTest/resources" )
compileClasspath = sourceSets.main.output +
configurations.integrationTestCompile
runtimeClasspath = output + compileClasspath +
configurations.integrationTestRuntime
}
}
that would add it for JavaPlugin
. If I manually wanted to add support for GroovyPlugin
, I could have added a line:
groovy.srcDir project.file( "src/integrationTest/groovy" )
For one, that is tedious and seocndly, not very fleixble for otehr languages. What I am trying to figure out if there is a way to automativally do this every time a new language is added (i.e. the plugin is applied). So if I where to do
apply plugin : 'scala'
I would want to see the equivalent of
scala.srcDir project.file( "src/integrationTest/scala" )
happen via some form of event i.e. a whenObjectAdded
kind of thing. I cannot do this on project.sourceSets
as whenObjectAdded
will trigger on the new SourceSet
i.e. integrationTest
being added, not on the SourceDirectorySet
. Her one might think that there is a requirementto find a way to discover that the new plugin being added is a JVM language plugin. Ther is curretntly no way of categorising plugins which is probably a good thing. This means that another way has to be found.
What I suspect is that the following will work if done in order.
apply plugin : 'add.integration.tests'
apply plugin : 'scala'
apply plugin : 'another.jvm.language'
This is due to the fact that JVM language plugins currently are supposed to do something like
sourceSets.each { SourceSet srcSet ->
final XyzSourceSet ss = new XyzSourceSet("Xyz language ${srcSet.name}",(project as ProjectInternal).fileResolver)
new DslObject(srcSet).convention.plugins.put('xyz',ss)
ss.xyz.srcDir("src/${srcSet.name}/xyz")
}
and at that point integrationTest
will already be in sourceSets
containers.
The problem is that we want to be independent of the order in which plugins are applied. What if the following written by a script author?
apply plugin : 'scala'
apply plugin : 'another.jvm.language'
apply plugin : 'add.integration.tests'
This is where I am stuck. How does the add.integration.tests
plugin discover which DirectorySourceSets
already exist?
`