Generate java.util.ServiceLoader manifests for your projects
This plugin is used to generate the META-INF/services/
manifest files used by the ServiceLoader
mechanism built into Java 6 (and higher). Using the service loader, you can specify a particular interface you want to load, and all implementations
which have an appropriate manifest on the classpath will be found an available to your application. This is particularly useful for SPI and Plugin
architectures.
apply plugin: 'com.github.delphyne.service-loader-manifest'
buildscript {
repositories {
maven {
url 'https://delphyne.github.io/.m2/'
}
}
dependencies {
classpath 'com.github.delphyne:gradle-service-loader-manifest:1.0.2'
}
}
repositories {
maven {
url 'https://delphyne.github.io/.m2/'
}
}
dependencies {
compile 'com.github.delphyne:gradle-service-loader-manifest:1.0.2'
}
apply plugin: 'com.github.delphyne.service-loader-manifest'
Add a serviceLoader
block to your build.gradle. For example, if you have an interface com.github.delphyne.Widget
serviceLoader {
serviceInterface 'com.github.delphyne.Widget'
}
Multiple interfaces may be provided to generate a manifest for each provided interface.
serviceLoader {
serviceInterface 'com.github.delphyne.Widget'
serviceInterface 'com.github.delphyne.Action'
}
or
serviceLoader {
serviceInterface 'com.github.delphyne.Widget', 'com.github.delphyne.Action'
}
or
serviceLoader {
serviceInterfaces = ['com.github.delphyne.Widget', 'com.github.delphyne.Action']
}
A GDSL file has been provided which will provide code completion within editors that support it.