As part of writing a Gradle plugin for Flyway, we stumbled upon a problem when dealing with Java migrations.
What is the best way to provide a Gradle plugin access on its classpath to the compiled classes of the project so that it can load and execute them?
So the situation is that we have a plugin that adds a task that wants to execute code contained in the project that the plugin is applied to. In this case, the task (class) should have an input property of type Iterable<File>
that gets configured (by the plugin) with the class path of the code to be executed (e.g. sourceSets.main.runtimeClasspath
). The task can then choose between the following ways to execute the code:
project.javaexec {}
to execute the code in a separate JVM. If the code isn't directly executable, the task may need to inject some bootstrap code onto the javaexec
class path. A potential alternative to using project.javaexec
is to use a JavaExec
task in the first place.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With