vvg
vvg

Reputation: 6385

SBT execute custom task on startup

SBT has a feature of managing project dependencies, where you can directly refer to an existing github project.

  val projectA = RootProject(uri("git://github.com/...."))
  val projectB = Project("projectB", file(".")) dependsOn(project)

Unfortunately, due to an existing bug - any changes in the dependent project (projectA) will not be reflected in a project that uses this dependency (projectB), even if you call sbt update.

https://github.com/sbt/sbt/issues/1284

It does not look like they will fix it soon.

But there is workaround: How do I refresh updated Git dependency artifacts in SBT? Removing ~/.sbt/staging/ helps. Apparently, this removal should happen during an early stage of project loading.

I've created simple task for removal, and defined it as a dependency to the update task - but it looks like it's too late and does not work as expected.

[info] Loading project definition from projectB
// next 4 stages are skipped if it's already cloned.
// Cloning into ... projectA 
// [info] Loading project definition from projectA
// [info] Updating projectA
// [info] Done updating.
[info] Updating projectB <<<--- where the removal is happening, too late...

What is the task that I can depend on?

Upvotes: 0

Views: 220

Answers (1)

vvg
vvg

Reputation: 6385

As for know, i've found a following solution. I've just defined method in my build.sbt, that returns empty Seq and perform necessary removal, and I'm invoking it directly in project definition, where settings are defined:

lazy val commonSettings = doRemove ++ Seq(... other settings.

Definitely non best practise approach, but does the work.

Upvotes: 0

Related Questions