Running java class for plugin execution


for a custom plugin, I need to run a class that needs to be created first, apart from the project’s own source and class files. So a class that is provided by the customplugin needs to be run, i.e. by being the main param of a JavaExec Task. However I have no idea how to best structure that process. I see the possibility to define 3 tasks in my plugin, one for generating the file into the buildDir, then one task to compile it, and one to run it. But that seems rather clumsy and complex. Or possibly I could try putting the custom plugin itself on the classpath of JavaExec.

Any tip on what approach seems best to you?



You can either call the program’s ‘main’ method directly (from a task action), or, if you need to run the program in a separate process, use a ‘JavaExec’ task. In the latter case, in order to determine the class path, you could package and resolve the program as a separate Jar, or try to infer the plugin’s Jar file location with something like ‘getClass().getProtectionDomain().getCodeSource().getLocation()’.