Skip to content

Commit a839c7e

Browse files
authored
Gradle Setup - Improve init script (#39)
1 parent 01446cf commit a839c7e

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed
Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1+
import org.gradle.util.GradleVersion
2+
13
def artifactoryUrl = '{{ .ArtifactoryURL }}'
24
def gradleRepoName = '{{ .GradleRepoName }}'
35
def artifactoryUsername = '{{ .ArtifactoryUsername }}'
46
def 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
625
gradle.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
2435
allprojects { 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

Comments
 (0)