Hi folks, is there a way to access sourceSets in t...
# gradle
s
Hi folks, is there a way to access sourceSets in the API? I’m translating the following Groovy bit
Copy code
task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allSource
}
s
sergei.lebedev:
Copy code
val sourceSets = java.sourceSets
val SourceSetContainer.main: SourceSet get() = this["main"]
val SourceSetContainer.test: SourceSet get() = this["test"]


val SourceSet.kotlin: SourceDirectorySet get() =
    (this as HasConvention).convention.getPlugin<KotlinSourceSet>().kotlin
👍 1
now you can access the sourceset like
sourceSets.main
s
Do you think it is possible to make this part of the official API?
Also: I can’t reference
java
, it refers to
java
the package.
m
i’ve had some wonkiness with the extension method generation before, you could also do
the<JavaPluginConvention>().sourceSets
s
Thanks! This does indeed work. Could you elaborate a bit on extension generation, is it supposed to be dynamic?
m
GSK generates extension methods for the actual extensions and convention objects applied by the plugins. so say you have you apply the
java
plugin which creates a convention object named
java
of type
JavaPluginConvention
. then a top level extension method
Project.java(JavaPluginConvention.() -> Unit): Unit
(something like that) is generated. the same is true for
extension
objects https://github.com/gradle/gradle-script-kotlin/releases/tag/v0.8.0 is more thorough and probably a better explanation than i can give
s
yeah for extension method generation , i always rely on
./gradlew gskGenerateAccessors
. After that you can refer
java
in your script.
s
I wonder why IntelliJ didn’t do this on import, hmm
Thanks @mkobit and @suresh!