Skip to content

Commit

Permalink
Merge pull request #646 from ihostage/sync-version
Browse files Browse the repository at this point in the history
Sync version between Sbt and Gradle
  • Loading branch information
mkurz authored Aug 11, 2023
2 parents 30e73ea + abebce3 commit 30016e1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
gradle-build-root: gradle-twirl
cmd: |
sbt validateCode
sbt compiler/publishM2
cd gradle-twirl && ./gradlew clean spotlessCheck --no-daemon
check-binary-compatibility:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ project/plugins/project/
.idea

.bloop/

compiler/version.properties
19 changes: 18 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.typesafe.tools.mima.core.Problem
import com.typesafe.tools.mima.core.ProblemFilters
import sbtcrossproject.CrossPlugin.autoImport.crossProject
import org.scalajs.jsenv.nodejs.NodeJSEnv
import java.util.Properties
import java.io.StringWriter

// Binary compatibility is this version
val previousVersion: Option[String] = Some("1.5.1")
Expand Down Expand Up @@ -58,6 +60,7 @@ lazy val twirl = project
(Compile / headerSources) ++=
((baseDirectory.value ** ("*.properties" || "*.md" || "*.sbt" || "*.scala.html"))
--- (baseDirectory.value ** "target" ** "*")
--- (baseDirectory.value / "compiler" / "version.properties")
--- (baseDirectory.value ** "gradle-twirl" ** "*") // Gradle Spotless plugin is used
--- (baseDirectory.value / "docs" ** "*")).get ++
(baseDirectory.value / "project" ** "*.scala" --- (baseDirectory.value ** "target" ** "*")).get
Expand Down Expand Up @@ -129,7 +132,10 @@ lazy val compiler = project
libraryDependencies += ("org.scalameta" %% "parsers" % "4.8.6").cross(CrossVersion.for3Use2_13),
run / fork := true,
buildInfoKeys := Seq[BuildInfoKey](scalaVersion),
buildInfoPackage := "play.twirl.compiler"
buildInfoPackage := "play.twirl.compiler",
publishM2 := publishM2.dependsOn(saveCompilerVersion).value,
publish := publish.dependsOn(saveCompilerVersion).value,
publishLocal := publishLocal.dependsOn(saveCompilerVersion).value
)
.aggregate(parser)
.dependsOn(apiJvm % Test, parser % "compile->compile;test->test")
Expand Down Expand Up @@ -172,6 +178,17 @@ def generateVersionFile =
Seq(file)
}

def saveCompilerVersion =
Def.task {
val props = new Properties()
val writer = new StringWriter()
val file = baseDirectory.value / "version.properties"
props.setProperty("twirl.compiler.version", version.value)
props.store(writer, "")
IO.write(file, writer.getBuffer.toString)
Seq(file)
}

addCommandAlias(
"validateCode",
List(
Expand Down
12 changes: 11 additions & 1 deletion gradle-twirl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.time.Duration
import java.util.Base64
import java.util.Properties
import kotlin.text.Charsets.UTF_8

plugins {
Expand All @@ -13,13 +14,22 @@ plugins {
signing
}

val compilerVersion: String =
Properties().apply {
val file = file("$projectDir/../compiler/version.properties")
if (!file.exists()) throw GradleException("Install Twirl Compiler to local Maven repository by `sbt compiler/publishM2` command")
file.inputStream().use { load(it) }
if (this.getProperty("twirl.compiler.version").isNullOrEmpty()) throw GradleException("`twirl.compiler.version` key didn't find in ${file.absolutePath}")
}.getProperty("twirl.compiler.version")

// group = "com.playframework" // group and plugin id must use same top level namespace
group = "com.typesafe.play" // TODO: uncomment line above and remove this
version = "0.0.1-SNAPSHOT"
version = compilerVersion

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
mavenLocal()
}

testing {
Expand Down

0 comments on commit 30016e1

Please sign in to comment.