1+ import org.gradle.util.GradleVersion
2+
13def artifactoryUrl = ' {{ .ArtifactoryURL }}'
24def gradleRepoName = ' {{ .GradleRepoName }}'
35def artifactoryUsername = ' {{ .ArtifactoryUsername }}'
46def artifactoryAccessToken = ' {{ .ArtifactoryAccessToken }}'
7+ def gradleVersion = GradleVersion . current()
8+ def allowInsecure = gradleVersion >= GradleVersion . version(" 6.2" ) && artifactoryUrl. startsWith(" http://" )
59
10+ void configureMavenRepo (repositories , String rtUrl , String rtUser , String rtPass , boolean allowInsecure ) {
11+ repositories. maven {
12+ url rtUrl
13+ credentials {
14+ username = rtUser
15+ password = rtPass
16+ }
17+ // This is used when Artifactory is running in HTTP mode
18+ if (allowInsecure) {
19+ allowInsecureProtocol = true
20+ }
21+ }
22+ }
23+
24+ // Configure the pluginManagement repositories
625gradle. settingsEvaluated { settings ->
726 settings. pluginManagement {
827 repositories {
9- maven {
10- url " ${ artifactoryUrl} /${ gradleRepoName} "
11- credentials {
12- username = artifactoryUsername
13- password = artifactoryAccessToken
14- }
15- }
16- if (artifactoryUrl. startsWith(" http://" )) {
17- allowInsecureProtocol = true
18- }
28+ configureMavenRepo(it, " ${ artifactoryUrl} /${ gradleRepoName} " , artifactoryUsername, artifactoryAccessToken, allowInsecure)
1929 gradlePluginPortal() // Fallback to Gradle Plugin Portal
2030 }
2131 }
2232}
2333
34+ // Configure the project repositories
2435allprojects { project ->
2536 project. repositories {
26- maven {
27- url " ${ artifactoryUrl} /${ gradleRepoName} "
28- credentials {
29- username = artifactoryUsername
30- password = artifactoryAccessToken
31- }
32- if (artifactoryUrl. startsWith(" http://" )) {
33- allowInsecureProtocol = true
34- }
35- }
37+ configureMavenRepo(it, " ${ artifactoryUrl} /${ gradleRepoName} " , artifactoryUsername, artifactoryAccessToken, allowInsecure)
3638 }
3739}
0 commit comments