From 7fcb17bf5d58b18f7ef34fe09d8ad2d2f579842d Mon Sep 17 00:00:00 2001 From: Bernie Schelberg Date: Fri, 13 Nov 2020 14:07:41 +1000 Subject: [PATCH] Exclude api and implementation configurations from pom dependencies --- .../plugins/shadow/ShadowJavaPlugin.groovy | 4 ++ .../plugins/shadow/PublishingSpec.groovy | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+) 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 f9ee14d2f..0b8b7aecc 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 @@ -105,7 +105,11 @@ class ShadowJavaPlugin implements Plugin { } upload.configuration = project.configurations.shadow MavenPom pom = upload.repositories.mavenDeployer.pom + if (project.configurations.findByName("api")) { + pom.scopeMappings.mappings.remove(project.configurations.api) + } pom.scopeMappings.mappings.remove(project.configurations.compile) + pom.scopeMappings.mappings.remove(project.configurations.implementation) pom.scopeMappings.mappings.remove(project.configurations.runtime) pom.scopeMappings.addMapping(MavenPlugin.RUNTIME_PRIORITY, project.configurations.shadow, Conf2ScopeMappingContainer.RUNTIME) } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy index 7a346b2bb..bd6614d8d 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy @@ -74,6 +74,53 @@ class PublishingSpec extends PluginSpecification { assert dependency.version.text() == '1.0' } + def "exclude api and implementation dependencies when publishing shadow jar with maven plugin"() { + given: + repo.module('shadow', 'a', '1.0') + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() + repo.module('shadow', 'b', '1.0') + .insertFile('b.properties', 'b') + .publish() + + settingsFile << "rootProject.name = 'maven'" + buildFile << """ + apply plugin: 'java-library' + apply plugin: 'maven' + + dependencies { + api 'shadow:a:1.0' + implementation 'shadow:b:1.0' + } + + uploadShadow { + repositories { + mavenDeployer { + repository(url: "${publishingRepo.uri}") + } + } + } + """.stripIndent() + + when: + runner.withArguments('uploadShadow').build() + + then: 'Check that shadow artifact exists' + File publishedFile = publishingRepo.rootDir.file('shadow/maven/1.0/maven-1.0-all.jar').canonicalFile + assert publishedFile.exists() + + and: 'Check contents of shadow artifact' + contains(publishedFile, ['a.properties', 'a2.properties']) + + and: 'Check that shadow artifact pom exists and contents' + File pom = publishingRepo.rootDir.file('shadow/maven/1.0/maven-1.0.pom').canonicalFile + assert pom.exists() + + def contents = new XmlSlurper().parse(pom) + assert contents.dependencies.size() == 0 + } + @Issue('SHADOW-347') def "maven install with application plugin"() { given: