Skip to content

Commit

Permalink
Generate version information when publishing artifacts (#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospereira authored Aug 24, 2020
1 parent 1a5fdf6 commit c878803
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ lazy val core = project
.enablePlugins(AutomateHeaderPlugin)
.disablePlugins(SitePlugin)
.settings(commonSettings)
.settings(VersionGenerator.settings)
.settings(
name := "akka-stream-kafka",
AutomaticModuleName.settings("akka.stream.alpakka.kafka"),
Expand Down
35 changes: 35 additions & 0 deletions project/VersionGenerator.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sbt._
import sbt.Keys._

/**
* Generate version.conf and akka/kafka/Version.scala files based on the version setting.
*
* This was adapted from https://github.com/akka/akka/blob/v2.6.8/project/VersionGenerator.scala
*/
object VersionGenerator {

val settings: Seq[Setting[_]] = inConfig(Compile)(
Seq(
resourceGenerators += generateVersion(resourceManaged, _ / "version.conf", """|akka.kafka.version = "%s"
|"""),
sourceGenerators += generateVersion(
sourceManaged,
_ / "akka" / "kafka" / "Version.scala",
"""|package akka.kafka
|
|object Version {
| val current: String = "%s"
|}
|"""
)
)
)

def generateVersion(dir: SettingKey[File], locate: File => File, template: String) = Def.task[Seq[File]] {
val file = locate(dir.value)
val content = template.stripMargin.format(version.value)
if (!file.exists || IO.read(file) != content) IO.write(file, content)
Seq(file)
}

}

0 comments on commit c878803

Please sign in to comment.