Skip to content

Commit

Permalink
Always declare Maven local repository at the top if exists (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Omico authored Jul 23, 2023
1 parent 7151f10 commit 3d7a1af
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/gradm-getting-started/gradm/gradm3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ versions:
spotless: "6.18.0"

repositories:
mavenLocal:
google:
mavenCentral:
jetbrainsCompose:
url: "https://maven.pkg.jetbrains.space/public/p/compose/dev"
mavenLocal:
sonatypeSnapshots:
url: "https://s01.oss.sonatype.org/content/repositories/snapshots"
gradlePluginPortal:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ versions:
spotless: "6.18.0"

repositories:
mavenLocal:
google:
mavenCentral:
jetbrainsCompose:
url: "https://maven.pkg.jetbrains.space/public/p/compose/dev"
mavenLocal:
sonatypeSnapshots:
url: "https://s01.oss.sonatype.org/content/repositories/snapshots"
gradlePluginPortal:
Expand Down
2 changes: 1 addition & 1 deletion examples/gradm-with-kotlin-multiplatform/gradm/gradm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ versions:
spotless: "6.18.0"

repositories:
mavenLocal:
google:
mavenCentral:
jetbrainsCompose:
url: "https://maven.pkg.jetbrains.space/public/p/compose/dev"
mavenLocal:
sonatypeSnapshots:
url: "https://s01.oss.sonatype.org/content/repositories/snapshots"
gradlePluginPortal:
Expand Down
2 changes: 1 addition & 1 deletion examples/template/gradm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ versions:
spotless: "6.18.0"

repositories:
mavenLocal:
google:
mavenCentral:
jetbrainsCompose:
url: "https://maven.pkg.jetbrains.space/public/p/compose/dev"
mavenLocal:
sonatypeSnapshots:
url: "https://s01.oss.sonatype.org/content/repositories/snapshots"
gradlePluginPortal:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import me.omico.gradm.GradmFormatConfiguration
import me.omico.gradm.internal.YamlDocument
import me.omico.gradm.internal.YamlObject
import me.omico.gradm.internal.asYamlDocument
import me.omico.gradm.internal.config.Repository
import me.omico.gradm.internal.config.buildInRepositories
import me.omico.gradm.internal.config.format.node.MappingNodeScope
import me.omico.gradm.internal.config.format.node.mapping
Expand Down Expand Up @@ -65,19 +66,27 @@ fun YamlScope.repositoriesSequence(document: YamlDocument) {
if (repositories.isEmpty()) return
newlineIfNeeded()
mapping("repositories") {
// Always place mavenLocal at the top
if (repositories.any { it.id == "mavenLocal" }) {
mapping("mavenLocal")
}
// Place build-in repositories
repositories
.filter { !it.noUpdates || it.id == "mavenLocal" }
.filterNot(Repository::noUpdates)
.forEach { repository ->
mapping(repository.id) repository@{
if (buildInRepositories.any { it.id == repository.id }) return@repository
if (repository in buildInRepositories) return@repository
scalar("url", repository.url, ScalarStyle.DoubleQuoted)
}
}
// Place no-updates repositories
repositories.find { it.id == "noUpdates" }?.id?.let(::mapping)
// Place custom no-updates repositories
repositories
.filterNot { it.id == "noUpdates" }
.filter { it.noUpdates && it.id != "mavenLocal" }
.sortedBy { it.id }
.filter(Repository::noUpdates)
.filterNot { it.id == "mavenLocal" }
.sortedBy(Repository::id)
.forEach { repository ->
mapping(repository.id) {
if (repository.url.isNotBlank()) {
Expand Down
2 changes: 1 addition & 1 deletion gradm-runtime/src/test/resources/gradm.unformatted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ versions:
okhttp: "4.9.3"

repositories:
mavenLocal:
customNoUpdates:
noUpdates: true
google:
Expand All @@ -29,6 +28,7 @@ repositories:
gradlePluginPortal:
url: "https://plugins.gradle.org/m2/"
noUpdates:
mavenLocal:

dependencies:
google:
Expand Down

0 comments on commit 3d7a1af

Please sign in to comment.