Skip to content

Commit 8d04b6b

Browse files
authored
Merge pull request #3178 from dotty-staging/fix-sbt-aggregate
Fix #3172: sbt-dotty breaks aggregrated tasks
2 parents de1d12e + 7d2acf0 commit 8d04b6b

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ object Build {
871871

872872

873873
sbtPlugin := true,
874-
version := "0.1.5",
874+
version := "0.1.6-SNAPSHOT",
875875
ScriptedPlugin.scriptedSettings,
876876
ScriptedPlugin.sbtTestDirectory := baseDirectory.value / "sbt-test",
877877
ScriptedPlugin.scriptedBufferLog := false,

sbt-dotty/src/dotty/tools/sbtplugin/DottyIDEPlugin.scala

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools.sbtplugin
22

33
import sbt._
4+
import sbt.Def.Initialize
45
import sbt.Keys._
56
import java.io._
67
import java.lang.ProcessBuilder
@@ -196,34 +197,38 @@ object DottyIDEPlugin extends AutoPlugin {
196197
origState
197198
}
198199

200+
private def projectConfigTask(config: Configuration): Initialize[Task[Option[ProjectConfig]]] = Def.task {
201+
if ((sources in config).value.isEmpty) None
202+
else {
203+
// Not needed to generate the config, but this guarantees that the
204+
// generated config is usable by an IDE without any extra compilation
205+
// step.
206+
val _ = (compile in config).value
207+
208+
val id = s"${thisProject.value.id}/${config.name}"
209+
val compilerVersion = (scalaVersion in config).value
210+
val compilerArguments = (scalacOptions in config).value
211+
val sourceDirectories = (unmanagedSourceDirectories in config).value ++ (managedSourceDirectories in config).value
212+
val depClasspath = Attributed.data((dependencyClasspath in config).value)
213+
val classDir = (classDirectory in config).value
214+
215+
Some(new ProjectConfig(
216+
id,
217+
compilerVersion,
218+
compilerArguments.toArray,
219+
sourceDirectories.toArray,
220+
depClasspath.toArray,
221+
classDir
222+
))
223+
}
224+
}
225+
199226
override def projectSettings: Seq[Setting[_]] = Seq(
200-
// Use Def.derive so `projectConfig` is only defined in the configurations where the
201-
// tasks/settings it depends on are defined.
202-
Def.derive(projectConfig := {
203-
if (sources.value.isEmpty) None
204-
else {
205-
// Not needed to generate the config, but this guarantees that the
206-
// generated config is usable by an IDE without any extra compilation
207-
// step.
208-
val _ = compile.value
209-
210-
val id = s"${thisProject.value.id}/${configuration.value.name}"
211-
val compilerVersion = scalaVersion.value
212-
val compilerArguments = scalacOptions.value
213-
val sourceDirectories = unmanagedSourceDirectories.value ++ managedSourceDirectories.value
214-
val depClasspath = Attributed.data(dependencyClasspath.value)
215-
val classDir = classDirectory.value
216-
217-
Some(new ProjectConfig(
218-
id,
219-
compilerVersion,
220-
compilerArguments.toArray,
221-
sourceDirectories.toArray,
222-
depClasspath.toArray,
223-
classDir
224-
))
225-
}
226-
})
227+
// TODO: It would be better to use Def.derive to define projectConfig in
228+
// every configuration where the keys it depends on exist, however this
229+
// currently breaks aggregated tasks: https://github.com/sbt/sbt/issues/3580
230+
projectConfig in Compile := projectConfigTask(Compile).value,
231+
projectConfig in Test := projectConfigTask(Test).value
227232
)
228233

229234
override def buildSettings: Seq[Setting[_]] = Seq(

0 commit comments

Comments
 (0)