diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2d2f9b..f3fb957 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -169,5 +169,5 @@ jobs: - name: Submit Dependencies uses: scalacenter/sbt-dependency-submission@v2 with: - modules-ignore: record4s_3 benchmark_2_11_2.11 record4s_3 benchmark_2_13_2.13 record4s_3 record4s_3 + modules-ignore: benchmark_3_3 benchmark_2_11_2.11 rootjs_3 benchmark_2_13_2.13 rootjvm_3 rootnative_3 configs-ignore: test scala-tool scala-doc-tool test-internal diff --git a/build.sbt b/build.sbt index 35d826f..9ad188d 100644 --- a/build.sbt +++ b/build.sbt @@ -1,8 +1,11 @@ -val groupId = "com.github.tarao" -val projectName = "record4s" -val rootPkg = s"$groupId.$projectName" +import ProjectKeys._ +import Implicits._ -ThisBuild / organization := groupId +ThisBuild / projectName := "record4s" +ThisBuild / groupId := "com.github.tarao" +ThisBuild / rootPkg := "${groupId.value}.${projectName.value}" + +ThisBuild / organization := groupId.value ThisBuild / organizationName := "record4s authors" ThisBuild / startYear := Some(2023) ThisBuild / licenses := Seq(License.MIT) @@ -12,8 +15,7 @@ ThisBuild / developers := List( ) lazy val metadataSettings = Def.settings( - name := projectName, - organization := groupId, + organization := groupId.value, description := "Extensible records for Scala", homepage := Some(url("https://github.com/tarao/record4s")), ) @@ -51,7 +53,7 @@ lazy val commonSettings = Def.settings( metadataSettings, compileSettings, initialCommands := s""" - import $rootPkg.* + import ${rootPkg.value}.* """, ) @@ -67,7 +69,7 @@ lazy val root = tlCrossRootProject lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform) .crossType(CrossType.Pure) .withoutSuffixFor(JVMPlatform) - .in(file("modules/core")) + .asModuleWithoutSuffix .settings(commonSettings) .settings( libraryDependencies ++= Seq( @@ -77,10 +79,12 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform) lazy val circe = crossProject(JVMPlatform, JSPlatform, NativePlatform) .crossType(CrossType.Pure) + .withoutSuffixFor(JVMPlatform) .dependsOn(core % "compile->compile;test->test") - .in(file("modules/circe")) + .asModule .settings(commonSettings) .settings( + description := "Circe integration for record4s", libraryDependencies ++= Seq( "io.circe" %%% "circe-core" % circeVersion, "io.circe" %%% "circe-generic" % circeVersion % Test, diff --git a/project/Implicits.scala b/project/Implicits.scala new file mode 100644 index 0000000..026f859 --- /dev/null +++ b/project/Implicits.scala @@ -0,0 +1,37 @@ +import sbt._ +import sbt.Keys._ +import sbtcrossproject.{CrossPlugin, CrossProject} +import scala.language.implicitConversions +import ProjectKeys.projectName + +object Implicits { + implicit class CrossProjectOps(private val p: CrossProject) extends AnyVal { + def asModuleWithoutSuffix: CrossProject = asModule(true) + + def asModule: CrossProject = asModule(false) + + private def asModule(noSuffix: Boolean): CrossProject = { + val project = p.componentProjects(0) + val s = project.settings(0) + p + .settings( + moduleName := { + if (noSuffix) + (ThisBuild / projectName).value + else + s"${(ThisBuild / projectName).value}-${(project / name).value}" + }, + CrossPlugin.autoImport.crossProjectBaseDirectory := { + val dir = file(s"modules/${(project / name).value}") + IO.resolve((LocalRootProject / baseDirectory).value, dir) + }, + ) + .configure(project => + project.in(file("modules") / project.base.getPath), + ) + } + } + + implicit def builderOps(b: CrossProject.Builder): CrossProjectOps = + new CrossProjectOps(b.build()) +} diff --git a/project/ProjectKeys.scala b/project/ProjectKeys.scala new file mode 100644 index 0000000..33da41d --- /dev/null +++ b/project/ProjectKeys.scala @@ -0,0 +1,7 @@ +import sbt.settingKey + +object ProjectKeys { + lazy val projectName = settingKey[String]("project name") + lazy val groupId = settingKey[String]("artifact group ID") + lazy val rootPkg = settingKey[String]("root package") +}