Hello all, I would like to write a Gradle plugin t...
# gradle
a
Hello all, I would like to write a Gradle plugin that access to developer's code. For example, If I write a class
Foo
in my Kotlin project and apply my plugin, I would like to get this compiled class
Foo
. Any hint regarding the topic?
o
it depends what you mean by "get", do you mean the source code, the compiled code for static analysis or transforms, or to actually load it into the classpath
a
I think more about the compiled code
o
assuming a standard setup where it is in the main sourceset, you can find it in
files(tasks.named("compileKotlin")).asFileTree
that FileTree contains files like
${projectRoot}/build/classes/kotlin/main/Foo.class
a
ok, thanks for your answer
To precise more my case
because it's perhaps not completely that ...
It's for Koin framework. People are using an API to declare a module: https://start.insert-koin.io/#/quickstart/kotlin?id=declaring-dependencies
I would like to "get" this
Module
variable from Gradle to be able to check it
o
that's going to be much more complicated. you need to load the class and probably the entire
runtimeClasspath
. I'm not very familiar with that myself so you'll have to ask someone else
a
ok, thanks 👍
m
Generally you can write something like anotation processor (you can have a look on https://github.com/Foso/MpApt or if you need a more power, compiler plugin can be also considered