Skip to content

Commit

Permalink
Only modify libs.versions.toml files
Browse files Browse the repository at this point in the history
  • Loading branch information
fthomas committed Jan 11, 2025
1 parent bbfd6ae commit 25cd7ac
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/repo-specific-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -967,15 +967,15 @@ 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]
|tomlj = { group = "org.tomlj", name = "tomlj", version.ref = "tomlj" }
|""".stripMargin
)
val expected = Map(
"gradle/libs.version.toml" ->
"gradle/libs.versions.toml" ->
"""|[versions]
|tomlj = "1.1.1"
|[libraries]
Expand Down

0 comments on commit 25cd7ac

Please sign in to comment.