Skip to content

Commit

Permalink
Fix module names.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarao committed Nov 8, 2023
1 parent 94fb684 commit 2ff832b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 13 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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")),
)
Expand Down Expand Up @@ -51,7 +53,7 @@ lazy val commonSettings = Def.settings(
metadataSettings,
compileSettings,
initialCommands := s"""
import $rootPkg.*
import ${rootPkg.value}.*
""",
)

Expand All @@ -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(
Expand All @@ -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,
Expand Down
37 changes: 37 additions & 0 deletions project/Implicits.scala
Original file line number Diff line number Diff line change
@@ -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())
}
7 changes: 7 additions & 0 deletions project/ProjectKeys.scala
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 2ff832b

Please sign in to comment.