Skip to content

Commit d2dcd99

Browse files
authored
Resolve settings dependencies from CodeArtifact (#3204)
1 parent 1982471 commit d2dcd99

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

build.gradle.kts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,10 @@ plugins {
1212
id("org.jetbrains.gradle.plugin.idea-ext")
1313
}
1414

15-
val codeArtifactUrl: Provider<String> = providers.environmentVariable("CODEARTIFACT_URL")
16-
val codeArtifactToken: Provider<String> = providers.environmentVariable("CODEARTIFACT_AUTH_TOKEN")
17-
1815
allprojects {
1916
repositories {
20-
if (codeArtifactUrl.isPresent && codeArtifactToken.isPresent) {
21-
println("Using CodeArtifact proxy: ${codeArtifactUrl.get()}")
22-
maven {
23-
url = uri(codeArtifactUrl.get())
24-
credentials {
25-
username = "aws"
26-
password = codeArtifactToken.get()
27-
}
28-
}
29-
}
17+
val codeArtifactMavenRepo: ((RepositoryHandler) -> Unit)? by extra
18+
codeArtifactMavenRepo?.invoke(this)
3019
mavenCentral()
3120
gradlePluginPortal()
3221
}

buildSrc/settings.gradle.kts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
val codeArtifactUrl: Provider<String> = providers.environmentVariable("CODEARTIFACT_URL")
4-
val codeArtifactToken: Provider<String> = providers.environmentVariable("CODEARTIFACT_AUTH_TOKEN")
3+
pluginManagement {
4+
repositories {
5+
val codeArtifactMavenRepo: ((RepositoryHandler) -> Unit)? by extra
6+
codeArtifactMavenRepo?.invoke(this)
7+
gradlePluginPortal()
8+
}
9+
}
510

611
dependencyResolutionManagement {
712
versionCatalogs {
@@ -11,16 +16,8 @@ dependencyResolutionManagement {
1116
}
1217

1318
repositories {
14-
if (codeArtifactUrl.isPresent && codeArtifactToken.isPresent) {
15-
println("Using CodeArtifact proxy: ${codeArtifactUrl.get()}")
16-
maven {
17-
url = uri(codeArtifactUrl.get())
18-
credentials {
19-
username = "aws"
20-
password = codeArtifactToken.get()
21-
}
22-
}
23-
}
19+
val codeArtifactMavenRepo: ((RepositoryHandler) -> Unit)? by extra
20+
codeArtifactMavenRepo?.invoke(this)
2421
mavenCentral()
2522
gradlePluginPortal()
2623
maven {

settings.gradle.kts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
val codeArtifactMavenRepo = fun RepositoryHandler.(): MavenArtifactRepository? {
4+
val codeArtifactUrl: Provider<String> = providers.environmentVariable("CODEARTIFACT_URL")
5+
val codeArtifactToken: Provider<String> = providers.environmentVariable("CODEARTIFACT_AUTH_TOKEN")
6+
return if (codeArtifactUrl.isPresent && codeArtifactToken.isPresent) {
7+
println("Using CodeArtifact proxy: ${codeArtifactUrl.get()}")
8+
maven {
9+
url = uri(codeArtifactUrl.get())
10+
credentials {
11+
username = "aws"
12+
password = codeArtifactToken.get()
13+
}
14+
}
15+
} else {
16+
null
17+
}
18+
}.also {
19+
pluginManagement {
20+
repositories {
21+
// janky because we need to apply to plugins in this file, but val falls out of scope
22+
it()
23+
gradlePluginPortal()
24+
}
25+
}
26+
}
27+
28+
extra["codeArtifactMavenRepo"] = codeArtifactMavenRepo
29+
330
rootProject.name = "aws-toolkit-jetbrains"
431

532
include("resources")

0 commit comments

Comments
 (0)