diff --git a/build.sbt b/build.sbt index 3747c2d9c..37ceb11f7 100644 --- a/build.sbt +++ b/build.sbt @@ -17,12 +17,13 @@ lazy val core = project .configs(IntegrationTest.extend(Test)) .settings(Defaults.itSettings) .settings( - name := "akka-persistence-jdbc", + name := "persistence-jdbc", libraryDependencies ++= Dependencies.Libraries, mimaReportSignatureProblems := true, mimaPreviousArtifacts := Set( - organization.value %% name.value % previousStableVersion.value.getOrElse( - throw new Error("Unable to determine previous version for MiMa")))) + organization.value %% name.value % "1.1.0")) + .settings(ReleaseAndPublish.getSettings) + lazy val migrator = project .in(file("migrator")) diff --git a/project/ProjectAutoPlugin.scala b/project/ProjectAutoPlugin.scala index c8035937f..bcc5a2b32 100644 --- a/project/ProjectAutoPlugin.scala +++ b/project/ProjectAutoPlugin.scala @@ -13,17 +13,19 @@ object ProjectAutoPlugin extends AutoPlugin { override def globalSettings = Seq( - organization := "com.lightbend.akka", - organizationName := "Lightbend Inc.", - organizationHomepage := Some(url("https://www.lightbend.com/")), + organization := "com.tencent.atum", + organizationName := "Tencent Inc.", + organizationHomepage := Some(url("https://www.tencent.com/")), homepage := Some(url("https://doc.akka.io/docs/akka-persistence-jdbc/current/")), scmInfo := Some( - ScmInfo(url("https://github.com/akka/akka-persistence-jdbc"), "git@github.com:akka/akka-persistence-jdbc.git")), + ScmInfo( + url("https://github.com/akka/akka-persistence-jdbc"), + "git@github.com:akka/akka-persistence-jdbc.git")), developers += Developer( - "contributors", - "Contributors", - "https://gitter.im/akka/dev", - url("https://github.com/akka/akka-persistence-jdbc/graphs/contributors")), + "contributors", + "Contributors", + "https://gitter.im/akka/dev", + url("https://github.com/akka/akka-persistence-jdbc/graphs/contributors")), licenses := Seq("Apache-2.0" -> url("https://opensource.org/licenses/Apache-2.0")), description := "A plugin for storing events in an event journal akka-persistence-jdbc", startYear := Some(2014)) @@ -38,27 +40,27 @@ object ProjectAutoPlugin extends AutoPlugin { Test / parallelExecution := false, Test / logBuffered := true, scalacOptions ++= Seq( - "-encoding", - "UTF-8", - "-unchecked", - "-Xlog-reflective-calls", - "-language:higherKinds", - "-language:implicitConversions", - "-target:jvm-1.8"), + "-encoding", + "UTF-8", + "-unchecked", + "-Xlog-reflective-calls", + "-language:higherKinds", + "-language:implicitConversions", + "-target:jvm-1.8"), Compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 13)) => - disciplineScalacOptions -- Set( - "-Ywarn-inaccessible", - "-Ywarn-infer-any", - "-Ywarn-nullary-override", - "-Ywarn-nullary-unit", - "-Ypartial-unification", - "-Yno-adapted-args") - case Some((2, 12)) => - disciplineScalacOptions - case _ => - Nil - }).toSeq, + case Some((2, 13)) => + disciplineScalacOptions -- Set( + "-Ywarn-inaccessible", + "-Ywarn-infer-any", + "-Ywarn-nullary-override", + "-Ywarn-nullary-unit", + "-Ypartial-unification", + "-Yno-adapted-args") + case Some((2, 12)) => + disciplineScalacOptions + case _ => + Nil + }).toSeq, scalacOptions += "-Ydelambdafy:method", Compile / doc / scalacOptions := scalacOptions.value ++ Seq( "-doc-title", diff --git a/project/ReleaseAndPublish.scala b/project/ReleaseAndPublish.scala new file mode 100644 index 000000000..cbe82a556 --- /dev/null +++ b/project/ReleaseAndPublish.scala @@ -0,0 +1,89 @@ +import sbtrelease.ReleasePlugin.autoImport._ +import sbtrelease.ReleaseStateTransformations._ +import sbt.Keys._ +import sbt.{ Def, _ } + +/** + * 管理Jar包的对外发布,包含两部分内容: + * - Publish 将jar包发布到maven仓库中 + * - Release 更新代码仓库的基线以及版本号 + * + * 该配置如果要启用,建议增加到工程的setting中,追加即可 + * + * 子工程单独发布: + * - 那么保证每个子工程的根目录下有version.sbt + * - version.sbt配置为"version := xxx" ,注意不要设置为"version in ThisBuild := xxx",否则依然会使用统一的版本号 + * - releaseUseGlobalVersion := false,确保不使用全局统一的版本号,每个子工程使用自己定义的内容 + * + * @note 目前暂不考虑使用sub project单独发布,因为这带给业务维护的巨大复杂性: + * - 子工程很多,每个子工程的版本号不一致,需要花费巨大精力考虑依赖关系和兼容性 + * - 作为公共库,应该对外保持一致性,如果使用sapp,那么sapp各个jar包的版本保持一致,那么业务只需要关注一个版本号即可。 + */ +object ReleaseAndPublish { + // NBA私有仓库地址,配置jar包发布仓库,基于内部私有的maven仓库,如果后续地址变更需要更新。 + private val privateReposAddress = "https://mirrors.tencent.com" + + // 版本发布相关的配置,包含发布的仓库,鉴权,发布内容等信息 + def getSettings: Seq[ + Def.Setting[_ >: Task[Option[Resolver]] with Task[Seq[Credentials]] with Boolean with Task[ + PublishConfiguration] with Seq[ReleaseStep] with Task[Seq[String]] with Task[String]]] = + Seq( + // release版本发布到nba-release目录下;snapshot版本发布到nba-snapshot目录下 + publishTo := { + Some( + "tencent-mirrors".at( + getPrivateRepositoryAddress(!(ThisBuild / version).value.endsWith("SNAPSHOT")))) + }, + //仓库的认证信息,按照规范,存在放个人目录下,不要配置在sbt文件中 + credentials += Credentials(Path.userHome / ".sbt" / ".credentials"), + // 添加源代码路径 + Compile / scalacOptions ++= { + Seq("-sourcepath", (LocalRootProject / baseDirectory).value.getAbsolutePath) + }, + // 允许sbt覆盖发布 jar 包,至于远程仓库是否可以覆盖,取决于远程仓库的权限配置,远程仓库无权限无法覆盖 + publishConfiguration := publishConfiguration.value.withOverwrite(true), + releaseTagName := getReleaseTagName.value, + releaseProcess := Seq[ReleaseStep]( + checkSnapshotDependencies, // 如果禁止依赖库中有snapshot,需要添加该项 + inquireVersions, // 版本获取 + runClean, // 构建前清理本地缓存 + releaseStepCommandAndRemaining("^ test"), // 运行测试用例,检查是否通过 + setReleaseVersion, // 更新版本号 + commitReleaseVersion, // 提交新的版本号到仓库 + tagRelease, + releaseStepCommandAndRemaining("^ publish"), + setNextVersion, // 设置下一个新版本 + commitNextVersion, // 提交新版本号到仓库 + pushChanges), + releaseUseGlobalVersion := true) + + /** + * 设定git打tag的命名前缀 + */ + private def getReleaseTagName: Def.Initialize[String] = + Def.setting { + s"${name.value}_v${if (releaseUseGlobalVersion.value) (ThisBuild / version).value + else version.value}" + } + + /** + * 获取atum私有maven仓库地址,包含命名和地址 + * + * @param release true表示是稳定版本,否则表示使用snapshot + */ + def getAtumPrivateRepository(release: Boolean = true): MavenRepository = { + val repoName = if (release) "release" else "snapshot" + s"atum-$repoName".at(getPrivateRepositoryAddress(release)) + } + + /** + * 获取本地仓库地址,注意仅仅是地址,不包含命名。release 和 snapshot 保存在不同repository 中。 + * [[https://stackoverflow.com/questions/275555/maven-snapshot-repository-vs-release-repository]] + * + * @param release true表示使用稳定版本,否则表示是使用snapshot + */ + private def getPrivateRepositoryAddress(release: Boolean): String = { + val repoName = if (release) "release" else "snapshot" + privateReposAddress + s"/repository/maven/atum-$repoName" + } +} diff --git a/project/plugins.sbt b/project/plugins.sbt index ab9b98042..c4edc9c63 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -7,6 +7,8 @@ addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.7.0") // release addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10") addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1") +addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") + // docs addSbtPlugin("com.lightbend.akka" % "sbt-paradox-akka" % "0.44") addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1") diff --git a/project/project-info.conf b/project/project-info.conf index 24ca2b565..3ca946a7d 100644 --- a/project/project-info.conf +++ b/project/project-info.conf @@ -28,8 +28,8 @@ project-info { ] } core: ${project-info.shared-info} { - title: "Akka Persistence JDBC" - jpms-name: "akka.persistence.jdbc" + title: "Persistence JDBC" + jpms-name: "persistence.jdbc" levels: [ { readiness: Supported diff --git a/version.sbt b/version.sbt new file mode 100644 index 000000000..848d48b1a --- /dev/null +++ b/version.sbt @@ -0,0 +1 @@ +ThisBuild / version := "5.1.0"