- This plugin is used to generate the
META-INF/services/
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 on the classpath will be found an available to your application. This is particularly useful for SPI and Plugin architectures.
https://plugins.gradle.org/plugin/com.github.harbby.gradle.serviceloader
Build script snippet for plugins DSL for Gradle 2.1 and later:
plugins {
id "com.github.harbby.gradle.serviceloader" version "1.1.2"
}
Build script snippet for use in older Gradle versions or where dynamic configuration is required:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.github.harbby:gradle-serviceloader:1.1.2"
}
}
apply plugin: "com.github.harbby.gradle.serviceloader"
Add a serviceLoader
to your build.gradle.
serviceLoader {
serviceInterface 'ideal.sylph.spi.Runner'
}
Multiple interfaces may be provided to generate a manifest for each provided interface.
serviceLoader {
serviceInterface 'ideal.xx.xx.XXInterface'
serviceInterface 'ideal.xx.xx.XXInterface'
}
The following is for testing
apply plugin: 'com.github.harbby.gradle.serviceloader'
buildscript {
repositories {
maven { url 'https://harbby.github.io/.m2/repository/' }
}
dependencies {
classpath 'com.github.harbby:gradle-serviceloader:1.1.2'
}
}