How to use SBT for interdependent projects in different configurations

I would like to have the following SBT assembly design:

object MyBuild extends Build { lazy val core = Project("core", file("core")) .dependsOn(testkit % "test") lazy val testkit = Project("testkit", file("testkit")) .dependsOn(core % "compile") } 

When core is the main module, including domain objects, and testkit is a module for testing support code (collectors, mappings, test drivers, etc., and not the tests themselves), which depend on domain objects and other / utils classes in core .

SBT gives a Cyclic reference error for this setting, although in fact there is no cyclic dependency due to the use of various configurations ( core compiles, then testkit compiles depending on core , then core test compiles depending on both).

I found a dirty way around this problem by replacing one of dependsOn use unmanagedClasspath , for example:

 .settings(unmanagedClasspath in Compile <+= (packageBin in (LocalProject("core"), Compile))) 

This seems like a hack, and also makes sbt-idea generate the wrong IntelliJ projects (by the way).

Any idea for a better solution? Does SBT support this structure?

+6
source share
1 answer

Sbt only checks projects when looking for circular dependencies. It does not take into account configurations. Dependency checking is performed in several places. One of the most important is in the LoadedBuild constructor.

This will require changes in a few places and probably some extensive tests. If you really want this feature, I think it could theoretically be added.

Closest you can go on to how sbt itself adds the dependency:

 lazy val core = project.in( file("core") ) .settings( internalDependencyClasspath in Test <++= exportedProducts in Compile in LocalProject("testkit") ) lazy val testkit = project.in( file("testkit") ) .settings( internalDependencyClasspath in Compile <++= exportedProducts in Compile in LocalProject("core") ) 
+2
source

Source: https://habr.com/ru/post/976203/


All Articles