From 05f0245323b81e6e578b7d567db1e808d309ad85 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Thu, 7 Jan 2021 00:57:53 +0300 Subject: [PATCH] =?UTF-8?q?gradle:=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D1=81=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B?= =?UTF-8?q?=20=D0=B2=20gradle-plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 59 ++++++++++++++++++++++++++++++++++------------------ libs.gradle | 1 + 2 files changed, 40 insertions(+), 20 deletions(-) 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',