diff --git a/artifactory/commands/gradle/resources/jfrog.init.gradle b/artifactory/commands/gradle/resources/jfrog.init.gradle index cba6f37e..66ca15d6 100644 --- a/artifactory/commands/gradle/resources/jfrog.init.gradle +++ b/artifactory/commands/gradle/resources/jfrog.init.gradle @@ -1,37 +1,39 @@ +import org.gradle.util.GradleVersion + def artifactoryUrl = '{{ .ArtifactoryURL }}' def gradleRepoName = '{{ .GradleRepoName }}' def artifactoryUsername = '{{ .ArtifactoryUsername }}' def artifactoryAccessToken = '{{ .ArtifactoryAccessToken }}' +def gradleVersion = GradleVersion.current() +def allowInsecure = gradleVersion >= GradleVersion.version("6.2") && artifactoryUrl.startsWith("http://") +void configureMavenRepo(repositories, String rtUrl, String rtUser, String rtPass, boolean allowInsecure) { + repositories.maven { + url rtUrl + credentials { + username = rtUser + password = rtPass + } + // This is used when Artifactory is running in HTTP mode + if (allowInsecure) { + allowInsecureProtocol = true + } + } +} + +// Configure the pluginManagement repositories gradle.settingsEvaluated { settings -> settings.pluginManagement { repositories { - maven { - url "${artifactoryUrl}/${gradleRepoName}" - credentials { - username = artifactoryUsername - password = artifactoryAccessToken - } - } - if (artifactoryUrl.startsWith("http://")) { - allowInsecureProtocol = true - } + configureMavenRepo(it, "${artifactoryUrl}/${gradleRepoName}", artifactoryUsername, artifactoryAccessToken, allowInsecure) gradlePluginPortal() // Fallback to Gradle Plugin Portal } } } +// Configure the project repositories allprojects { project -> project.repositories { - maven { - url "${artifactoryUrl}/${gradleRepoName}" - credentials { - username = artifactoryUsername - password = artifactoryAccessToken - } - if (artifactoryUrl.startsWith("http://")) { - allowInsecureProtocol = true - } - } + configureMavenRepo(it, "${artifactoryUrl}/${gradleRepoName}", artifactoryUsername, artifactoryAccessToken, allowInsecure) } } \ No newline at end of file