I'm trying to understand the difference between a ...
# gradle
m
I'm trying to understand the difference between a Kotlin: • target • compilation • sourceSet Something that has bugged me for a while is that I would intuitively expect the dependencies to be set on "compilations" and not "sourceSets" but I've never really taken the time to dig into this. Does anyone have any pointers?
h
It's the source code that has dependencies – therefore dependencies are defined on a source set. At least that's how I understood it, so far… I haven't heard of "target" or "compilation" as named Gradle concepts yet, could you please explain a little bit more, what you mean?
m
Can't explain too much since I'm also making my way through this but you can do this:
Copy code
// add JVM target
val jvmTarget = kotlin.jvm() 
// add a compilation to the JVM target
val myCompilation = jvmTarget.compilations.create("myCompilation")
// get the default source set for this comilation
myCompilation.defaultSourceSet
source code that has dependencies
At the end you need to pass those dependencies to the compiler and compile a "set" of "sourceSets" altogether? Or at least this is my mental model
e
as far as I understand, target = environment where the compiled code is expected to run compilation = unit of work for the compiler source set = 1 leaf per compilation, but with some number of parents
👍 1
m
Ah, so a compilation takes only one leaf source set and then gets the parents through
dependsOn
and can get the dependencies as it goes 👍 Makes sense, thanks!
Can I create a compilation without creating a target? If I want to just run some tests but don't care about a framework or jar file
e
no, but you can create additional compilations within a target
👍 1
thank you color 1
t
since Kotlin 1.9.20 consider 1 compilation that will compile one
defaultKotlinSourceSet
via one compilation task. Indeed it could include additional sources from shared
KotlinSourceSet
.
KotlinTarget
may contain 1 or more
KotlinCompilation
. Usually it is two - production code and test code compilations.
👍 1
m
Thanks! If I create a new compilation on the
jvm
target, will its default source set depend on
commonMain
by default or do I have to wire that myself?
t
as far as I see - you need to do it manually
👍 1
m
Thanks, I think it's better this way for my use case actually.
t
btw what is your use-case for creating additional compilation?
m
Currently digging into this
We have some integration tests of the Apollo plugin where we want to substitute the Kotlin models for the equivalent Java models
So if the new default sourceSet was to depend on
commonMain
, we would end up with duplicate symbols because the Kotlin models are configured there already