Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark Missing Local Artifacts as optional #23245

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant to link to the issue here?

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"
}
}
Expand Up @@ -60,7 +60,12 @@ public static ResolvedVariant create(@Nullable VariantResolveMetadata.Identifier

private static Supplier<ResolvedArtifactSet> supplyResolvedArtifactSet(DisplayName displayName, AttributeContainerInternal attributes, CapabilitiesMetadata capabilities, Supplier<Collection<? extends ResolvableArtifact>> artifactsSupplier) {
return () -> {
Collection<? extends ResolvableArtifact> artifacts = artifactsSupplier.get();
Collection<? extends ResolvableArtifact> artifacts;
try {
artifacts = artifactsSupplier.get();
} catch (Exception e) {
return EMPTY;
}
if (artifacts.isEmpty()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there was an easy way to pass information about whether we are resolving leniently or strictly to the ArtifactBackedResolvedVariant#create method as it calls supplyResolvedArtifacts so that we can add this (or similar error handling) when this supplier's get() is called, this would be a straightforward change, I think.

Alternately, if we could change the Supplier to a Function and pass in the configuration doing the resolving when get()/call() is called, we could do the same thing.

As it is now, passing this information all the way into this Supplier when it is created seems like it would require sending a flag down a very long chain of resolution calls.

return EMPTY;
}
Expand Down
Expand Up @@ -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;
}
}