From 8d01d41e86d4b0b18c8c803c5ad55f2bf5c082a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20M=C3=BCller?= Date: Fri, 9 Apr 2021 19:58:06 +0200 Subject: [PATCH] Allow for opt-out of the java shadowRuntimeElements variant --- .../gradle/plugins/shadow/ShadowExtension.groovy | 2 ++ .../gradle/plugins/shadow/ShadowJavaPlugin.groovy | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy index 307265794..65237d54b 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy @@ -12,10 +12,12 @@ class ShadowExtension { CopySpec applicationDistribution Project project + boolean addJavaVariants ShadowExtension(Project project) { this.project = project applicationDistribution = project.copySpec {} + addJavaVariants = true } void component(MavenPublication publication) { diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy index 670683700..192d7f056 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy @@ -50,9 +50,13 @@ class ShadowJavaPlugin implements Plugin { project.configurations.shadowRuntimeElements.extendsFrom project.configurations.shadow - project.components.java { - addVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { - mapToOptional() // make it a Maven optional dependency + project.afterEvaluate { + if (project.extensions.findByName(ShadowBasePlugin.EXTENSION_NAME).addJavaVariants) { + project.components.java { + addVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { + mapToOptional() // make it a Maven optional dependency + } + } } } }