diff --git a/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/PluginUtils.java b/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/PluginUtils.java index 7e2b6d2..34256cb 100644 --- a/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/PluginUtils.java +++ b/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/PluginUtils.java @@ -4,6 +4,7 @@ import org.gradle.api.GradleException; import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import org.gradle.api.invocation.Gradle; +import org.gradle.authentication.http.BasicAuthentication; import org.jfrog.build.api.builder.ModuleType; import org.jfrog.build.api.util.Log; import org.jfrog.build.client.Version; @@ -67,6 +68,12 @@ public static void addArtifactoryResolutionRepositoryAction(MavenArtifactReposit credentials.setUsername(username); credentials.setPassword(password); }); + + // Before resolving an artifact from Artifactory, Gradle typically sends a preemptive challenge request and + // expects a 401 response from the server. + // However, when 'Hide Existence of Unauthorized Resources' is enabled, Artifactory returns a 404 instead. + // Adding BasicAuthentication ensures that credentials are sent directly, bypassing this challenge. + mavenArtifactRepository.authentication(authentications -> authentications.create("basic", BasicAuthentication.class)); } }