diff --git a/buildSrc/subprojects/packaging/src/main/kotlin/org/gradle/gradlebuild/packaging/ShadedJarPlugin.kt b/buildSrc/subprojects/packaging/src/main/kotlin/org/gradle/gradlebuild/packaging/ShadedJarPlugin.kt index 76f75c62e43d..9ae39f3caa37 100644 --- a/buildSrc/subprojects/packaging/src/main/kotlin/org/gradle/gradlebuild/packaging/ShadedJarPlugin.kt +++ b/buildSrc/subprojects/packaging/src/main/kotlin/org/gradle/gradlebuild/packaging/ShadedJarPlugin.kt @@ -233,6 +233,10 @@ open class ShadedJarPlugin : Plugin { tasks.named("sourcesJar") { from(sourcesPath.incoming.artifactView { lenient(true) }.files) } + val sourcesElements by configurations + sourcesElements.attributes { + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.SHADOWED)) + } } private diff --git a/subprojects/tooling-api/src/integTest/groovy/org/gradle/integtests/tooling/ToolingApiResolveIntegrationTest.groovy b/subprojects/tooling-api/src/integTest/groovy/org/gradle/integtests/tooling/ToolingApiResolveIntegrationTest.groovy new file mode 100644 index 000000000000..03a5586ee44b --- /dev/null +++ b/subprojects/tooling-api/src/integTest/groovy/org/gradle/integtests/tooling/ToolingApiResolveIntegrationTest.groovy @@ -0,0 +1,102 @@ +/* + * Copyright 2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.gradle.integtests.tooling + +import org.gradle.integtests.fixtures.AbstractIntegrationSpec +import org.gradle.util.GradleVersion +import spock.lang.Unroll + +class ToolingApiResolveIntegrationTest extends AbstractIntegrationSpec { + + @Unroll + def "can resolve tooling API via #configuration"() { + given: + def tapiVersion = GradleVersion.current().version + buildFile << """ + plugins { + id 'java-library' + } + repositories { + maven { url '${buildContext.libsRepo.toURI().toURL()}' } + ${mavenCentralRepository()} + } + + configurations { customConf } + + dependencies { + implementation 'org.gradle:gradle-tooling-api:${tapiVersion}' + customConf 'org.gradle:gradle-tooling-api:${tapiVersion}' + } + + tasks.register('resolve') { + doLast { + println configurations.${configuration}.files.collect { it.name } + } + } + """ + + when: + succeeds 'resolve' + + then: + outputContains("[gradle-tooling-api-${tapiVersion}.jar, slf4j-api-1.7.28.jar]") + + where: + configuration << ['compileClasspath', 'runtimeClasspath', 'customConf'] + } + + def "can resolve sources variant of tooling API"() { + given: + def tapiVersion = GradleVersion.current().version + buildFile << """ + plugins { + id 'java-library' + } + repositories { + maven { url '${buildContext.libsRepo.toURI().toURL()}' } + ${mavenCentralRepository()} + } + + configurations { + sources { + extendsFrom runtimeClasspath + canBeConsumed = false + visible = false + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, DocsType.SOURCES)) + } + } + } + + dependencies { + implementation "org.gradle:gradle-tooling-api:${tapiVersion}" + } + + tasks.register('resolve') { + doLast { + println configurations.sources.files.collect { it.name } + } + } + """ + + when: + succeeds 'resolve' + + then: + outputContains("[gradle-tooling-api-${tapiVersion}-sources.jar]") + } +}