I am creating a CLI application in Kotlin with Gradle (Kotlin DSL) as the build system. The CLI will support plugins that will be loaded via ServiceLoader
. In order to do so, the plugins must be in the classpath, and I want users to be able to load their own plugins easily.
I thought about a default directory for the plugin jar files, e.g. $HOME/.my-app/plugins
, and add it to the classpath, so that ServiceLoader
can discover the plugins.
I am planning to compile the application with the application
Gradle plugin. Is there a way to add $HOME/.my-app/plugins
to the classpath in the Gradle build configuration in a platform-independent way? I don’t quite know how to do so, since the structure of the home directory depends on the OS.
Am I on the right path? Or is there a simpler way to manage plugin installations?