Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to latest sbt version and refactor Java version validation #42

Merged
merged 4 commits into from
Feb 1, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Validate required Java version in misc subproject.
Previously, validation of required version was done during loading of
build definition. This was needlessly restricting because not everything
in scalariform requires particular Java version. After closer inspection,
it turns out that only the `misc` subproject depends on Swing and cares
about the specific Java version.

We refactor validation logic to run right before `compile` task in `misc`
subproject. That makes it possible to ignore this subproject and build the
rest of scalariform on any Java version.
  • Loading branch information
gkossakowski committed Jan 22, 2015
commit ada232e023362ca262072af4ba7339612ecc0b41
15 changes: 12 additions & 3 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ object ScalariformBuild extends Build {

// This is to make sure nobody tries to compile with 1.6 as the target JDK.
// Not clear if this will actually work on 1.8, needs to be tested when that is out.
val specVersion = sys.props("java.specification.version")
val validateJavaVersion = taskKey[Unit]("Check if we are running using required Java version")
val mismatchedSpecificationMessage =
"""|Java 1.7 is required for building Scalariform.
"""|Java 1.7 is required for building the `misc` subproject of Scalariform.
|
|This is due to a dependency on the javax.swing library, which
|had an API change from 1.6 to 1.7.
|
|Using 1.7 to build requires setting SBT to use JDK 1.7 or higher -- if SBT is
|booting on JDK 1.6, you will get a javax.swing related compilation error.""".stripMargin
assert(specVersion == "1.7", mismatchedSpecificationMessage)

lazy val commonSettings = Defaults.defaultSettings ++ SbtScalariform.defaultScalariformSettings ++ sonatypeSettings ++ Seq(
organization := "com.danieltrinh",
Expand Down Expand Up @@ -109,6 +108,16 @@ object ScalariformBuild extends Build {
"com.miglayout" % "miglayout" % "3.7.4"),
publish := (),
publishLocal := (),
validateJavaVersion := {
val specJavaVersion = sys.props("java.specification.version")
val compatibleJavaVersion = specJavaVersion == "1.7" || specJavaVersion == "1.8"
if (!compatibleJavaVersion)
sys.error(mismatchedSpecificationMessage)
},
// this means we'll validate required Java version only _right before_ running the compile
// command in misc subproject. In particular, build won't fail if user is not interested
// in building `misc` subproject.
compile in Compile := ((compile in Compile) dependsOn validateJavaVersion).value,
mainClass in (Compile, run) := Some("scalariform.gui.Main"))) dependsOn (scalariform, cli)

def pomExtraXml =
Expand Down