Skip to content

Commit

Permalink
Merge pull request #48 from hmrc/BDOG-2885
Browse files Browse the repository at this point in the history
BDOG-2885 Build for Play 3.0
  • Loading branch information
oscarduignan authored Nov 23, 2023
2 parents cc7dee1 + ee1c5c1 commit c7eb544
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 47 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ These helpers allow for the formatting of dates, in both English and Welsh.

There was an API change from version 4.x.x to 5.x.x, to remove the deprecated `joda.time` library from `play-language`.

From version 5.0.0 onwards, dates should be passed in as instances of `java.time.LocalDate`, not `joda.time.LocalDate`,
From version 5.0.0 onwards, dates should be passed in as instances of `java.time.LocalDate`, not `joda.time.LocalDate`,
and dates with times should be passed in as instances of `java.time.LocalDateTime`, not `joda.time.DateTime`.

## Setup (for play-ui users only)

Add the library to the project dependencies:

``` scala
libraryDependencies += "uk.gov.hmrc" %% "play-language" % "[INSERT VERSION]"
libraryDependencies += "uk.gov.hmrc" %% "play-language-play-xx" % "[INSERT VERSION]"
```

Where play-xx is your version of Play (e.g. play-29).

Ensure to add the resolvers to your `plugins.sbt`:

```scala
Expand Down Expand Up @@ -55,10 +57,10 @@ class CustomLanguageController @Inject()(
if (appConfig.welshLanguageSupportEnabled) Map(en -> Lang(en), cy -> Lang(cy))
else Map(en -> Lang(en))
}

override def fallbackURL: String =
"https://www.gov.uk/government/organisations/hm-revenue-customs"

}
```

Expand Down Expand Up @@ -120,7 +122,7 @@ class AppConfig @Inject()(languageUtils: LanguageUtils) {

#### Using [govuk-template]("https://github.com/hmrc/govuk-template"):
Pass the following arguments to your template renderer
``` scala
``` scala
"langSelector" -> {
Map(
"enUrl" -> controllers.routes.CustomLanguageController.switchToLanguage("english"),
Expand All @@ -132,5 +134,5 @@ Pass the following arguments to your template renderer
```

## License ##

This code is open source software licensed under the [Apache 2.0 License]("http://www.apache.org/licenses/LICENSE-2.0.html").
98 changes: 80 additions & 18 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,29 +1,91 @@
import sbt.Keys._
import scala.collection.JavaConverters._

val scala2_12 = "2.12.15"
val scala2_13 = "2.13.7"
val scala2_12 = "2.12.18"
val scala2_13 = "2.13.12"

val silencerVersion = "1.7.7"
ThisBuild / majorVersion := 7
ThisBuild / isPublicArtefact := true
ThisBuild / scalaVersion := scala2_13
ThisBuild / scalacOptions += "-Wconf:src=views/.*:s"
ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always // required since we're cross building for Play 2.8 which isn't compatible with sbt 1.9

lazy val playLanguage = (project in file("."))
.enablePlugins(PlayScala)
.disablePlugins(PlayLayoutPlugin)
lazy val projects: Seq[ProjectReference] =
sys.env.get("PLAY_VERSION") match {
case Some("2.8") => Seq(playLanguage, playLanguagePlay28)
case Some("2.9") => Seq(playLanguagePlay29)
case _ => Seq(playLanguagePlay30)
}

lazy val library = (project in file("."))
.settings(publish / skip := true)
.aggregate(
projects: _*
)

// empty artefact, exists to ensure eviction of previous play-language jar which has now moved into play-language-play-28
lazy val playLanguage = Project("play-language", file("play-language"))
.settings(crossScalaVersions := Seq(scala2_12, scala2_13))

def copySources(module: Project) = Seq(
Compile / scalaSource := (module / Compile / scalaSource).value,
Compile / resourceDirectory := (module / Compile / resourceDirectory).value,
Test / scalaSource := (module / Test / scalaSource).value,
Test / resourceDirectory := (module / Test / resourceDirectory).value
)

lazy val playLanguagePlay28 = Project("play-language-play-28", file("play-language-play-28"))
.enablePlugins(
SbtTwirl
) // previously used play sbt-plugin and enabled PlayScala and disabled PlayLayout - this was overkill to add templateImports, and added lots of unnecessary dependencies to created binary (incl. Main-Class config in Manifest)
.disablePlugins(JUnitXmlReportPlugin) //Required to prevent https://github.com/scalatest/scalatest/issues/1427
.settings(copySources(playLanguagePlay30))
.settings(
majorVersion := 6,
name := "play-language",
scalaVersion := scala2_12,
crossScalaVersions := Seq(scala2_12, scala2_13),
PlayCrossCompilation.playCrossCompilationSettings,
libraryDependencies ++= AppDependencies.all,
isPublicArtefact := true,
scalacOptions += "-P:silencer:pathFilters=views",
libraryDependencies ++= Seq(
compilerPlugin("com.github.ghik" % "silencer-plugin" % silencerVersion cross CrossVersion.full),
"com.github.ghik" % "silencer-lib" % silencerVersion % Provided cross CrossVersion.full
libraryDependencies ++= AppDependencies.play28
)
.settings(
Compile / TwirlKeys.compileTemplates / sourceDirectories ++=
(Compile / unmanagedSourceDirectories).value,
TwirlKeys.templateImports ++= Seq(
"play.api.mvc._",
"play.api.data._",
"play.api.i18n._"
)
)
.dependsOn(playLanguage)

lazy val playLanguagePlay29 = Project("play-language-play-29", file("play-language-play-29"))
.enablePlugins(SbtTwirl)
.disablePlugins(JUnitXmlReportPlugin) //Required to prevent https://github.com/scalatest/scalatest/issues/1427
.settings(copySources(playLanguagePlay30))
.settings(
Compile / TwirlKeys.compileTemplates / sourceDirectories +=
(Compile / sourceDirectory).value / "scala"
crossScalaVersions := Seq(scala2_13),
libraryDependencies ++= AppDependencies.play29
)
.settings(
Compile / TwirlKeys.compileTemplates / sourceDirectories ++=
(Compile / unmanagedSourceDirectories).value,
TwirlKeys.templateImports ++= Seq(
"play.api.mvc._",
"play.api.data._",
"play.api.i18n._"
)
)

lazy val playLanguagePlay30 = Project("play-language-play-30", file("play-language-play-30"))
.enablePlugins(SbtTwirl)
.disablePlugins(JUnitXmlReportPlugin) //Required to prevent https://github.com/scalatest/scalatest/issues/1427
.settings(
crossScalaVersions := Seq(scala2_13),
libraryDependencies ++= AppDependencies.play30
)
.settings(
Compile / TwirlKeys.compileTemplates / sourceDirectories ++=
(Compile / unmanagedSourceDirectories).value,
TwirlKeys.templateImports ++= Seq(
"play.api.mvc._",
"play.api.data._",
"play.api.i18n._"
)
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
@Html(" | ")
}
}
</p>
</p>
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.play.language

/*
* play-language has been replaced with play-language-play-xx.
* See [uk.gov.hmrc.play.language.LanguageController]
*/
private class PlayLanguageLibraryHasMoved
48 changes: 35 additions & 13 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,45 @@
*/

import sbt._
import play.core.PlayVersion

object AppDependencies {

val compile: Seq[ModuleID] = PlayCrossCompilation.dependencies(
shared = Seq(
"com.ibm.icu" % "icu4j" % "69.1",
"com.typesafe.play" %% "play" % PlayVersion.current
)
)
val play28 = play("play-28")
val play29 = play("play-29")
val play30 = play("play-30")

val test: Seq[ModuleID] = PlayCrossCompilation.dependencies(
play28 = Seq(
"org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test,
"com.vladsch.flexmark" % "flexmark-all" % "0.35.10" % Test
)
private def play(playSuffix: String) = Seq(
"com.ibm.icu" % "icu4j" % "69.1",
playOrg(playSuffix) %% "play" % playVersion(playSuffix),
"org.scalatestplus.play" %% "scalatestplus-play" % scalaTestPlusPlayVersion(playSuffix) % Test,
"com.vladsch.flexmark" % "flexmark-all" % flexmarkAllVersion(playSuffix) % Test
)

val all: Seq[ModuleID] = compile ++ test
private def playVersion(playSuffix: String) =
playSuffix match {
case "play-28" => "2.8.20"
case "play-29" => "2.9.0"
case "play-30" => "3.0.0"
}

private def playOrg(playSuffix: String): String =
playSuffix match {
case "play-28" => "com.typesafe.play"
case "play-29" => "com.typesafe.play"
case "play-30" => "org.playframework"
}

private def scalaTestPlusPlayVersion(playSuffix: String): String =
playSuffix match {
case "play-28" => "5.1.0"
case "play-29" => "6.0.0"
case "play-30" => "7.0.0"
}

private def flexmarkAllVersion(playSuffix: String): String =
playSuffix match {
case "play-28" => "0.36.8"
case "play-29" => "0.64.8"
case "play-30" => "0.64.8"
}
}
4 changes: 0 additions & 4 deletions project/PlayCrossCompilation.scala

This file was deleted.

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.6.2
sbt.version=1.9.7
17 changes: 13 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefac
resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(
Resolver.ivyStylePatterns
)
resolvers += Resolver.typesafeRepo("releases")

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.18")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.8.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-play-cross-compilation" % "2.3.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.15.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.0")

sys.env.get("PLAY_VERSION") match {
case Some("2.8") => // required since we're cross building for Play 2.8 which isn't compatible with sbt 1.9
libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always
case _ => libraryDependencySchemes := libraryDependencySchemes.value // or any empty DslEntry
}

sys.env.get("PLAY_VERSION") match {
case Some("2.8") => addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.1")
case Some("2.9") => addSbtPlugin("com.typesafe.play" % "sbt-twirl" % "1.6.1")
case _ => addSbtPlugin("org.playframework.twirl" % "sbt-twirl" % "2.0.1")
}
1 change: 1 addition & 0 deletions repository.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
repoVisibility: public_0C3F0CE3E6E6448FAD341E7BFA50FCD333E06A20CFF05FCACE61154DDBBADF71
type: library

0 comments on commit c7eb544

Please sign in to comment.