From 5f8196dd570f0ec5d6add476ed20a35b8d984af8 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Sat, 18 Apr 2020 18:39:23 -0700 Subject: [PATCH] Cross build for Scala.js 1.x and 0.6 --- .travis.yml | 8 +++++++- build.sbt | 2 ++ project/plugins.sbt | 4 +++- project/plugins.sbt.scala-js.0.6 | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 project/plugins.sbt.scala-js.0.6 diff --git a/.travis.yml b/.travis.yml index d88d89f..176ecbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,8 +31,14 @@ before_deploy: deploy: - provider: script - script: sbt ++$TRAVIS_SCALA_VERSION "set every Seq(sonatypeSessionName := \"Travis Job $TRAVIS_JOB_NAME $TRAVIS_JOB_NUMBER ($TRAVIS_JOB_WEB_URL)\", publishTo := sonatypePublishToBundle.value)" publishSigned sonatypeBundleRelease + script: sbt $SBT_ARGS ++$TRAVIS_SCALA_VERSION "set every Seq(sonatypeSessionName := \"Travis Job $TRAVIS_JOB_NAME $TRAVIS_JOB_NUMBER ($TRAVIS_JOB_WEB_URL)\", publishTo := sonatypePublishToBundle.value)" publishSigned sonatypeBundleRelease skip_cleanup: true on: all_branches: true condition: $GITHUB_PERSONAL_ACCESS_TOKEN + +env: + - SBT_ARGS= + - SBT_ARGS=--addPluginSbtFile=project/plugins.sbt.scala-js.0.6 + +sbt_args: $SBT_ARGS diff --git a/build.sbt b/build.sbt index 4254e94..d50ad02 100644 --- a/build.sbt +++ b/build.sbt @@ -1,3 +1,5 @@ +import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType} + organization in ThisBuild := "com.thoughtworks.sde" publish / skip := true diff --git a/project/plugins.sbt b/project/plugins.sbt index 692968d..569054f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,7 +2,9 @@ addSbtPlugin("com.thoughtworks.sbt-best-practice" % "sbt-best-practice" % "7.2.0 addSbtPlugin("com.thoughtworks.sbt-scala-js-map" % "sbt-scala-js-map" % "4.0.0") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.32") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1") + +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8") diff --git a/project/plugins.sbt.scala-js.0.6 b/project/plugins.sbt.scala-js.0.6 new file mode 100644 index 0000000..4be2b43 --- /dev/null +++ b/project/plugins.sbt.scala-js.0.6 @@ -0,0 +1,22 @@ +// An optional sbt file to replace Scala.js 1.0 with 0.6 +dependencyOverrides += Defaults.sbtPluginExtra( + "org.scala-js" % "sbt-scalajs" % "0.6.32", + sbtBinaryVersion.value, + scalaBinaryVersion.value, +) + +Compile / sourceGenerators += Def.task { + val file = (Compile / sourceManaged).value / "SkipPublishForNonScalaJSProjects.scala" + IO.write(file, """ + import scalajscrossproject.ScalaJSCrossPlugin.autoImport._ + import sbtcrossproject.CrossPlugin.autoImport._ + import sbt._, Keys._ + object SkipPublishForNonScalaJSProjects extends AutoPlugin { + override def trigger = allRequirements + override def projectSettings = Seq( + publish / skip := crossProjectPlatform.value != JSPlatform + ) + } + """) + Seq(file) +}.taskValue