@@ -213,7 +213,9 @@ object Build {
213213 // on a task. Instead, we make `compile` below depend on the bridge `packageSrc`
214214 Some ((artifactPath in (`dotty-sbt-bridge`, Compile , packageSrc)).value.toURI.toURL))),
215215 compile in Compile := (compile in Compile )
216- .dependsOn(packageSrc in (`dotty-sbt-bridge`, Compile )).value,
216+ .dependsOn(packageSrc in (`dotty-sbt-bridge`, Compile ))
217+ .dependsOn(compile in (`dotty-sbt-bridge`, Compile ))
218+ .value,
217219
218220 // Use the same name as the non-bootstrapped projects for the artifacts
219221 moduleName ~= { _.stripSuffix(" -bootstrapped" ) },
@@ -746,18 +748,29 @@ object Build {
746748 // until sbt/sbt#2402 is fixed (https://github.com/sbt/sbt/issues/2402)
747749 lazy val cleanSbtBridge = TaskKey [Unit ](" cleanSbtBridge" , " delete dotty-sbt-bridge cache" )
748750
751+ def cleanSbtBridgeImpl (): Unit = {
752+ val home = System .getProperty(" user.home" )
753+ val sbtOrg = " org.scala-sbt"
754+ val bridgePattern = s " *dotty-sbt-bridge* $dottyVersion* "
755+
756+ IO .delete((file(home) / " .sbt" / " 1.0" / " zinc" / sbtOrg * bridgePattern).get)
757+ IO .delete((file(home) / " .sbt" / " boot" * " scala-*" / sbtOrg / " sbt" * " *" * bridgePattern).get)
758+ }
759+
749760 lazy val dottySbtBridgeSettings = Seq (
750761 cleanSbtBridge := {
751- val home = System .getProperty(" user.home" )
752- val sbtOrg = " org.scala-sbt"
753- val bridgeDirectoryPattern = s " * $dottyVersion* "
754-
762+ cleanSbtBridgeImpl()
763+ },
764+ compile in Compile := {
755765 val log = streams.value.log
756- log.info(" Cleaning the dotty-sbt-bridge cache" )
757- IO .delete((file(home) / " .ivy2" / " cache" / sbtOrg * bridgeDirectoryPattern).get)
758- IO .delete((file(home) / " .sbt" / " boot" * " scala-*" / sbtOrg / " sbt" * " *" * bridgeDirectoryPattern).get)
766+ val prev = (previousCompile in Compile ).value.analysis.orElse(null )
767+ val cur = (compile in Compile ).value
768+ if (prev != cur) {
769+ log.info(" Cleaning the dotty-sbt-bridge cache because it was recompiled." )
770+ cleanSbtBridgeImpl()
771+ }
772+ cur
759773 },
760- compile in Compile := (compile in Compile ).dependsOn(cleanSbtBridge).value,
761774 description := " sbt compiler bridge for Dotty" ,
762775 resolvers += Resolver .typesafeIvyRepo(" releases" ), // For org.scala-sbt:api
763776 libraryDependencies ++= Seq (
0 commit comments