From a50e351c5856b51b544253e41a1572eb87a0bbf0 Mon Sep 17 00:00:00 2001 From: Justin Kaeser Date: Thu, 16 Aug 2018 18:01:54 +0300 Subject: [PATCH] don't warn when current sbt version doesn't match version in build.properties when version is set by system property. mitigates https://github.com/sbt/sbt/issues/4303 --- main/src/main/scala/sbt/Main.scala | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main/src/main/scala/sbt/Main.scala b/main/src/main/scala/sbt/Main.scala index 0e592984d..50d11993b 100644 --- a/main/src/main/scala/sbt/Main.scala +++ b/main/src/main/scala/sbt/Main.scala @@ -780,21 +780,30 @@ object BuiltinCommands { def checkSBTVersionChanged(state: State): Unit = { import sbt.io.syntax._ - val app = state.configuration.provider + val sbtVersionProperty = "sbt.version" + + // Don't warn if current version has been set in system properties + val sbtVersionSystemOpt = + Option(System.getProperty(sbtVersionProperty)) + + // the intention is to warn if build.properties file has changed during current sbt session + // a `reload` will not respect this change while `reboot` will. val buildProps = state.baseDir / "project" / "build.properties" - // First try reading the sbt version from build.properties file. - val sbtVersionOpt = if (buildProps.exists) { + val sbtVersionBuildOpt = if (buildProps.exists) { val buildProperties = new Properties() IO.load(buildProperties, buildProps) - Option(buildProperties.getProperty("sbt.version")) + Option(buildProperties.getProperty(sbtVersionProperty)) } else None + val sbtVersionOpt = sbtVersionSystemOpt.orElse(sbtVersionBuildOpt) + + val app = state.configuration.provider sbtVersionOpt.foreach( version => if (version != app.id.version()) { state.log.warn(s"""sbt version mismatch, current: ${app.id .version()}, in build.properties: "$version", use 'reboot' to use the new value.""") - } + } ) }