diff --git a/build.gradle b/build.gradle index d3e550b..a0c0d7e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,44 @@ +class FilteringDependenciesExtention { + + /** + * example for 'library': + *
+     * [lib: 'org.bukkit:bukkit:1.12.2-R0.1-SNAPSHOT',
+     * exclude: [
+     *   'com.google.code.gson:gson',
+     *   'com.googlecode.json-simple:json-simple'
+     * ]]
+     * 
+ * + * @param library see example + */ + def filter(library) { + Object[] result = new Object[2] + result[0] = library.lib + result[1] = { + library.exclude.each { String excludeLibStr -> + String[] excludeLib = excludeLibStr.split(':') + exclude group: excludeLib[0], module: excludeLib[1] + } + } + + return result + } +} + +class FilteringDependenciesPlugin implements Plugin { + + @Override + void apply(Project target) { + target.extensions.create('fildep', FilteringDependenciesExtention) + } +} + plugins { id 'java' } +apply plugin: FilteringDependenciesPlugin apply from: 'libs.gradle' def publishScript = file(rootProject.getProjectDir().getPath() + '/publish.gradle') @@ -19,35 +56,17 @@ repositories { maven { url 'https://dmx-mc-project.gitlab.io/maven-repository/' } } -def compileOnly2(library) { - dependencies.compileOnly library.lib, { - library.exclude.each { String excludeLibStr -> - String[] excludeLib = excludeLibStr.split(':') - exclude group: excludeLib[0], module: excludeLib[1] - } - } -} - -def testImplementation2(library) { - dependencies.testImplementation library.lib, { - library.exclude.each { String excludeLibStr -> - String[] excludeLib = excludeLibStr.split(':') - exclude group: excludeLib[0], module: excludeLib[1] - } - } -} - dependencies { compileOnly libs.lombok annotationProcessor libs.lombok - compileOnly2 libs.bukkit + compileOnly fildep.filter(libs.bukkit) implementation libs.commons_text implementation libs.refobj testImplementation libs.test.junit5 testImplementation libs.test.mock - testImplementation2 libs.bukkit + testImplementation fildep.filter(libs.bukkit) testImplementation libs.test.h2db } diff --git a/libs.gradle b/libs.gradle index 2ee7fee..d39f9fa 100644 --- a/libs.gradle +++ b/libs.gradle @@ -1,6 +1,7 @@ ext { versions = [junit: '5.5.2'] + //noinspection GroovyAssignabilityCheck libs = [ bukkit : [lib: 'org.bukkit:bukkit:1.12.2-R0.1-SNAPSHOT', exclude: [ 'com.google.code.gson:gson',