/gradle-serviceloader

gradle java spi plugin

Primary LanguageJavaApache License 2.0Apache-2.0

Build Status

gradle-serviceloader

  • 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.

Installation

https://plugins.gradle.org/plugin/com.github.harbby.gradle.serviceloader

build.gradle

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"

Usage

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'
}

other

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'
 	}
 }