I maintain a static analysis tool, the <Dependency...
# library-development
t
I maintain a static analysis tool, the Dependency Analysis Gradle Plugin. When analyzing KMP projects, it would be very useful if I could directly access, in a read-only way, the source set tree. I can iterate over the source sets, but knowing their hierarchy would make my analysis easier. Is this something the maintainers of KGP would be open to?
✅ 1
@tapchicoma, Zac suggested I mention this to you
o
KGP does provide that information: TestBalloon has a
testBalloonDiagnostics
task which creates a hierarchical Mermaid diagram from source sets. Maybe you could adapt the idea?
y
AbstractKotlinSourceSet
lets you access the dependsOn closure, which might be useful here? It is under the
internal
package though, so not part of the normal API surface FWIW, source sets aren't actually in a "tree" in the strictest sense. More like a DAG I think?
o
org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
has
public abstract val dependsOn: Set<KotlinSourceSet>
, which is public.
true 1
y
Yes, but the transitive closure isn't, although you can just calculate it recursively I've found the transitive closure useful sometimes, so figured it's worth a mention
o
Do we need it in this case?
t
I tried accessing the
dependsOn
and it was empty in every case. Maybe I accessed it "too early" and some lazy configuration hadn't realized yet?
ok, I'll try that again and do it in a lazier way. I tried something very similar to what the testBalloon code you linked is doing
o
Yep. You need to wait until source sets are configured. Try in a task action. Or, if that's infeasible,
afterEvaluate
(but that's always risky because of the evaluation order).
t
I'll try afterEvaluate to start as a POC. But ultimately I would want to do it in a task action
👍 1
👍🏻 1
ok! that works. That's all I need. Thank you!
kodee welcoming 2
t
source set tree has final form on quite late stage of configuration because of peculiarities how users may enable KMP targets and KGP has internal mechanism to do it around
afterEvaluate
stage. That is why I am not sure that for us it is easy to expose read access to source set tree kodee sad
t
yeah I can see how that would be tricky. Luckily, I was able to feed the information lazily into a task and read its final state in the task action. I can easily build the graph from the dependsOn relationships
👍 1