From 25cd7ac340c90f2211d580b1fe45fa837c7e5ab6 Mon Sep 17 00:00:00 2001 From: Frank Thomas Date: Sat, 11 Jan 2025 12:04:02 +0100 Subject: [PATCH] Only modify libs.versions.toml files --- docs/repo-specific-configuration.md | 2 +- .../core/buildtool/gradle/GradleAlg.scala | 10 ++----- .../core/buildtool/gradle/package.scala | 26 +++++++++++++++++++ .../core/repoconfig/UpdatesConfig.scala | 13 +++++----- .../core/buildtool/gradle/GradleAlgTest.scala | 4 +-- .../scalasteward/core/edit/RewriteTest.scala | 8 +++--- 6 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 modules/core/src/main/scala/org/scalasteward/core/buildtool/gradle/package.scala diff --git a/docs/repo-specific-configuration.md b/docs/repo-specific-configuration.md index 19a2a76fd..66590d532 100644 --- a/docs/repo-specific-configuration.md +++ b/docs/repo-specific-configuration.md @@ -130,7 +130,7 @@ updates.allowPreReleases = [ { groupId = "com.example", artifactId="foo" } ] updates.limit = 5 # The extensions of files that should be updated. -# Default: [".mill",".mill-version",".sbt",".sbt.shared",".sc",".scala",".scalafmt.conf",".sdkmanrc",".toml",".yml","build.properties","mill-version","pom.xml"] +# Default: [".mill",".mill-version",".sbt",".sbt.shared",".sc",".scala",".scalafmt.conf",".sdkmanrc",".yml","build.properties","libs.versions.toml","mill-version","pom.xml"] updates.fileExtensions = [".scala", ".sbt", ".sbt.shared", ".sc", ".yml", ".md", ".markdown", ".txt"] # If "on-conflicts", Scala Steward will update the PR it created to resolve conflicts as diff --git a/modules/core/src/main/scala/org/scalasteward/core/buildtool/gradle/GradleAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/buildtool/gradle/GradleAlg.scala index 96e4160ca..292ca5182 100644 --- a/modules/core/src/main/scala/org/scalasteward/core/buildtool/gradle/GradleAlg.scala +++ b/modules/core/src/main/scala/org/scalasteward/core/buildtool/gradle/GradleAlg.scala @@ -43,16 +43,10 @@ final class GradleAlg[F[_]](defaultResolver: Resolver)(implicit .map(gradleParser.parseDependenciesAndPlugins) .map { case (dependencies, plugins) => val ds = Option.when(dependencies.nonEmpty)(Scope(dependencies, List(defaultResolver))) - val ps = Option.when(plugins.nonEmpty)(Scope(plugins, List(GradleAlg.pluginsResolver))) + val ps = Option.when(plugins.nonEmpty)(Scope(plugins, List(pluginsResolver))) ds.toList ++ ps.toList } private def libsVersionsToml(buildRoot: BuildRoot): F[File] = - workspaceAlg.buildRootDir(buildRoot).map(_ / "gradle" / "libs.versions.toml") - -} - -object GradleAlg { - val pluginsResolver: Resolver.MavenRepository = - Resolver.MavenRepository("gradle-plugins", "https://plugins.gradle.org/m2/", None, None) + workspaceAlg.buildRootDir(buildRoot).map(_ / "gradle" / libsVersionsTomlName) } diff --git a/modules/core/src/main/scala/org/scalasteward/core/buildtool/gradle/package.scala b/modules/core/src/main/scala/org/scalasteward/core/buildtool/gradle/package.scala new file mode 100644 index 000000000..a98de6153 --- /dev/null +++ b/modules/core/src/main/scala/org/scalasteward/core/buildtool/gradle/package.scala @@ -0,0 +1,26 @@ +/* + * Copyright 2018-2025 Scala Steward contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.scalasteward.core.buildtool + +import org.scalasteward.core.data.Resolver + +package object gradle { + val libsVersionsTomlName = "libs.versions.toml" + + val pluginsResolver: Resolver.MavenRepository = + Resolver.MavenRepository("gradle-plugins", "https://plugins.gradle.org/m2/", None, None) +} diff --git a/modules/core/src/main/scala/org/scalasteward/core/repoconfig/UpdatesConfig.scala b/modules/core/src/main/scala/org/scalasteward/core/repoconfig/UpdatesConfig.scala index 6c31bb796..40582f158 100644 --- a/modules/core/src/main/scala/org/scalasteward/core/repoconfig/UpdatesConfig.scala +++ b/modules/core/src/main/scala/org/scalasteward/core/repoconfig/UpdatesConfig.scala @@ -22,11 +22,10 @@ import eu.timepit.refined.types.numeric.NonNegInt import io.circe.generic.semiauto.deriveCodec import io.circe.refined.* import io.circe.{Codec, Decoder} -import org.scalasteward.core.buildtool.maven.pomXmlName import org.scalasteward.core.buildtool.mill.MillAlg -import org.scalasteward.core.buildtool.sbt.buildPropertiesName +import org.scalasteward.core.buildtool.{gradle, maven, sbt} import org.scalasteward.core.data.{GroupId, Update} -import org.scalasteward.core.scalafmt.scalafmtConfName +import org.scalasteward.core.scalafmt import org.scalasteward.core.update.FilterAlg.{ FilterResult, IgnoredByConfig, @@ -112,12 +111,12 @@ object UpdatesConfig { ".sbt.shared", ".sc", ".scala", - scalafmtConfName, ".sdkmanrc", - ".toml", ".yml", - buildPropertiesName, - pomXmlName + gradle.libsVersionsTomlName, + maven.pomXmlName, + sbt.buildPropertiesName, + scalafmt.scalafmtConfName ) val defaultLimit: Option[NonNegInt] = None diff --git a/modules/core/src/test/scala/org/scalasteward/core/buildtool/gradle/GradleAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/buildtool/gradle/GradleAlgTest.scala index af4f5accf..31118ff8f 100644 --- a/modules/core/src/test/scala/org/scalasteward/core/buildtool/gradle/GradleAlgTest.scala +++ b/modules/core/src/test/scala/org/scalasteward/core/buildtool/gradle/GradleAlgTest.scala @@ -14,7 +14,7 @@ class GradleAlgTest extends CatsEffectSuite { val buildRootDir = workspaceAlg.buildRootDir(buildRoot).unsafeRunSync() val initial = MockState.empty.addFiles( - buildRootDir / "gradle" / "libs.versions.toml" -> + buildRootDir / "gradle" / libsVersionsTomlName -> """|[libraries] |tomlj = { group = "org.tomlj", name = "tomlj", version = "1.1.1" } |[plugins] @@ -26,7 +26,7 @@ class GradleAlgTest extends CatsEffectSuite { "org.jetbrains.kotlin.jvm".g % "org.jetbrains.kotlin.jvm.gradle.plugin".a % "2.1.20-Beta1" val expected = List( List("org.tomlj".g % "tomlj".a % "1.1.1").withMavenCentral, - Scope(List(kotlinJvm), List(GradleAlg.pluginsResolver)) + Scope(List(kotlinJvm), List(pluginsResolver)) ) assertIO(obtained, expected) } diff --git a/modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala b/modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala index afe187930..68d153a20 100644 --- a/modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala +++ b/modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala @@ -950,13 +950,13 @@ class RewriteTest extends FunSuite { test("Gradle Version Catalog") { val update = ("org.tomlj".g % "tomlj".a % "1.0.0" %> "1.1.1").single val original = Map( - "gradle/libs.version.toml" -> + "gradle/libs.versions.toml" -> """|[libraries] |tomlj = { group = "org.tomlj", name = "tomlj", version = "1.0.0" } |""".stripMargin ) val expected = Map( - "gradle/libs.version.toml" -> + "gradle/libs.versions.toml" -> """|[libraries] |tomlj = { group = "org.tomlj", name = "tomlj", version = "1.1.1" } |""".stripMargin @@ -967,7 +967,7 @@ class RewriteTest extends FunSuite { test("Gradle Version Catalog with version.ref") { val update = ("org.tomlj".g % "tomlj".a % "1.0.0" %> "1.1.1").single val original = Map( - "gradle/libs.version.toml" -> + "gradle/libs.versions.toml" -> """|[versions] |tomlj = "1.0.0" |[libraries] @@ -975,7 +975,7 @@ class RewriteTest extends FunSuite { |""".stripMargin ) val expected = Map( - "gradle/libs.version.toml" -> + "gradle/libs.versions.toml" -> """|[versions] |tomlj = "1.1.1" |[libraries]