Matthew Laser
09/28/2021, 7:22 PMephemient
09/28/2021, 7:39 PMandroid {
libraryVariants.all {
registerJavaGeneratingTask(myTaskProvider, myTaskOutputDirectory)
}
}
ephemient
09/28/2021, 7:45 PMephemient
09/28/2021, 7:45 PMval myTask by tasks.registering {
outputs.dir(layout.buildDirectory.dir("generated/source/my"))
doLast {
for (fileSpec in myFileSpecs) {
fileSpec.writeTo(outputs.files.singleFile)
}
}
}
Matthew Laser
09/28/2021, 7:45 PMMatthew Laser
09/28/2021, 7:47 PMlibraryVariants.all
version you posted first, I'm not familiar what type of argument myTaskProvider
would be, though it sounds familiar based on research I was doing on KSP (though hope to avoid using it if possible)ephemient
09/28/2021, 8:10 PMephemient
09/28/2021, 8:11 PMMatthew Laser
09/28/2021, 8:51 PMMyGenerator
with a function generate()
, that when invoked uses KotlinPoet to build files and write them to directory build/generated/MyGeneratedCode
using FileSpec.writeTo()
2. Somehow gradle executes a task prior to assemble
that calls`MyGenerator.generate()`
3. Gradle builds a library that uses the code inside of build/generated/MyGeneratedCode
so that it can create a jar
or aar
that contains this code under the package com.mycompany.MyGeneratedCode
I'm sure I'm off here, but this is what I picture happening. If you have time, can you correct my understanding? If not, thanks for the help so far 🙂ephemient
09/28/2021, 8:57 PMbuild/generated/MyGeneratedCode
should then get compiled just like other code within src/main/java
, not a separate jar/aarMatthew Laser
09/28/2021, 9:01 PMMyGenerator.generate()
)?ephemient
09/28/2021, 9:06 PMephemient
09/28/2021, 9:07 PMephemient
09/28/2021, 9:08 PMMatthew Laser
09/28/2021, 9:10 PMMatthew Laser
09/28/2021, 9:16 PMobject
with dozens of functions, for instance,
• GoogleAPI.foo(arg: Int)
• GoogleAPI.bar(arg: Boolean)
etc....
My plan was to use kotlin-reflect to take the input class (GoogleAPI
), iterate through all its functions, and create "wrapper classes" for each member function of GoogleAPI
using KotlinPoet, of a format like (notice class foo
is generated because of GoogleAPI.foo
)
class foo() {
val arg: Int
fun execute() {
GoogleAPI.foo(arg)
}
}
Matthew Laser
09/28/2021, 9:16 PMephemient
09/28/2021, 9:51 PMephemient
09/28/2021, 9:52 PMMatthew Laser
09/28/2021, 9:53 PMephemient
09/28/2021, 9:57 PMMatthew Laser
09/28/2021, 10:03 PMMatthew Laser
09/28/2021, 10:04 PM