diff --git a/subprojects/dependency-management/src/integTest/groovy/org/gradle/integtests/resolve/ResolvePOMSpec.groovy b/subprojects/dependency-management/src/integTest/groovy/org/gradle/integtests/resolve/ResolvePOMSpec.groovy new file mode 100644 index 000000000000..42e20d56255b --- /dev/null +++ b/subprojects/dependency-management/src/integTest/groovy/org/gradle/integtests/resolve/ResolvePOMSpec.groovy @@ -0,0 +1,124 @@ +/* + * Copyright 2022 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.resolve + +import org.gradle.integtests.fixtures.AbstractIntegrationSpec +import spock.lang.Issue + +@Issue("https://github.com/gradle/gradle/pull/23245") +class ResolvePOMSpec extends AbstractIntegrationSpec { + def "resolving a @pom artifact from an included build replacing an external library doesn't fail the build"() { + given: + def mainProjectDir = file("main-project") + def includedLoggingProjectDir = file("included-logging") + + mainProjectDir.file("settings.gradle.kts").text = """ + rootProject.name = "main-project" + include("app") + includeBuild("../included-logging") + """ + + mainProjectDir.file("app/build.gradle.kts").text = """ + plugins { + application + } + + dependencies { + implementation("org.gradle.repro:lib@pom") + } + """ + + includedLoggingProjectDir.file("settings.gradle.kts").text = """ + rootProject.name = "included-logging" + include("lib") + """ + + includedLoggingProjectDir.file("lib/build.gradle.kts").text = """ + plugins { + `java-library` + } + """ + + includedLoggingProjectDir.file("gradle.properties").text = """ + group=org.gradle.repro + version=0.1.0-SNAPSHOT + """ + + executer.inDirectory(mainProjectDir) + + expect: + succeeds "build" + } + + def "getting the file for a @pom artifact from an included build replacing an external library doesn't fail the build"() { + given: + def mainProjectDir = file("main-project") + def includedLoggingProjectDir = file("included-logging") + + mainProjectDir.file("settings.gradle.kts").text = """ + rootProject.name = "main-project" + include("app") + includeBuild("../included-logging") + """ + + mainProjectDir.file("app/build.gradle.kts").text = """ + plugins { + application + } + + dependencies { + implementation("org.gradle.repro:lib@pom") + } + + tasks.register("resolve") { + doLast { + val c: Configuration = configurations.getByName("compileClasspath") + c.getResolvedConfiguration() + .getLenientConfiguration() + .getAllModuleDependencies() + .map { it.getAllModuleArtifacts() } + .forEach { mas -> + mas.forEach { a -> + println(a.getFile()) + } + } + } + } + """ + + includedLoggingProjectDir.file("settings.gradle.kts").text = """ + rootProject.name = "included-logging" + include("lib") + """ + + includedLoggingProjectDir.file("lib/build.gradle.kts").text = """ + plugins { + `java-library` + } + """ + + includedLoggingProjectDir.file("gradle.properties").text = """ + group=org.gradle.repro + version=0.1.0-SNAPSHOT + """ + + executer.inDirectory(mainProjectDir) + + expect: + succeeds "resolve" + } +} diff --git a/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/ivyservice/resolveengine/artifact/ArtifactBackedResolvedVariant.java b/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/ivyservice/resolveengine/artifact/ArtifactBackedResolvedVariant.java index 195bfa5ca160..f1973aedeff5 100644 --- a/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/ivyservice/resolveengine/artifact/ArtifactBackedResolvedVariant.java +++ b/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/ivyservice/resolveengine/artifact/ArtifactBackedResolvedVariant.java @@ -60,7 +60,12 @@ public static ResolvedVariant create(@Nullable VariantResolveMetadata.Identifier private static Supplier supplyResolvedArtifactSet(DisplayName displayName, AttributeContainerInternal attributes, CapabilitiesMetadata capabilities, Supplier> artifactsSupplier) { return () -> { - Collection artifacts = artifactsSupplier.get(); + Collection artifacts; + try { + artifacts = artifactsSupplier.get(); + } catch (Exception e) { + return EMPTY; + } if (artifacts.isEmpty()) { return EMPTY; } diff --git a/subprojects/dependency-management/src/main/java/org/gradle/internal/component/local/model/MissingLocalArtifactMetadata.java b/subprojects/dependency-management/src/main/java/org/gradle/internal/component/local/model/MissingLocalArtifactMetadata.java index 38e3fb767e83..2d38e0f92ed3 100644 --- a/subprojects/dependency-management/src/main/java/org/gradle/internal/component/local/model/MissingLocalArtifactMetadata.java +++ b/subprojects/dependency-management/src/main/java/org/gradle/internal/component/local/model/MissingLocalArtifactMetadata.java @@ -98,4 +98,9 @@ public boolean equals(Object obj) { MissingLocalArtifactMetadata other = (MissingLocalArtifactMetadata) obj; return other.componentIdentifier.equals(componentIdentifier) && other.name.equals(name); } + + @Override + public boolean isOptionalArtifact() { + return false; + } }