I am trying to write a Kotlin Gradle application that will dynamically compile and run .jar source code files during runtime.
The Gradle project would be compiled to a jar and then receive the directory path of these .java files as CLI arguments. The contents, directory path, package and dependencies of these .java files are not known to the Gradle application during compilation.
I was thinking it would be possible to parse the text of the source code to see what imports and package it belongs to and then apply the classpaths of a source set that is pre-defined the Gradle build file. For that I would need to be able to the get access to the project’s sourceSets and apply their classpaths dynamically when I compile the inputted .java files.
Another option I thought about is pulling the required dependency from the repo dynamically during runtime to provide the required classpaths of the inputted .java file being compiled.
Not sure if either of these are possible. Thank you in advance. Any guidance or examples would be appreciated.