I have a multi-project contains a private macro sub-project which's usage is limited to implement method body of other sub-projects. Neither should it be on the runtime classpath of other sub-projects, nor should it be visible in any form in the published POM of other sub-projects. So that other sbt project could use library from this project without knowing the macro sub-project.
For external dependency, I found this SO Q&A works perfectly, but for sub-project when I trying to do the similar thing to dependsOn
, sbt complains about configuration "compileonly" not found.
ivyConfigurations += config("compileonly").hide
val macro = Project("macro", file("macro"))
val lib = Project("lib", file("lib")).dependsOn(macro % "compile->compileonly")
That error is because the project doesn't have that config.
val CompileOnly = config("compileonly").hide
ivyConfigurations += CompileOnly
val macro = Project("macro", file("macro")).configs(CompileOnly) // add config
val lib = Project("lib", file("lib")).dependsOn(macro % CompileOnly)
But then the problem is
macro#macro_2.10;0.1-SNAPSHOT: configuration not public in macro#macro_2.10;0.1-SNAPSHOT: 'compileonly'. It was required from lib#lib_2.10;0.1-SNAPSHOT compile
The solution is
val CompileOnly = config("compileonly")
val macro = Project("macro", file("macro")).configs(CompileOnly)
val lib = Project("lib", file("lib")).dependsOn(macro % CompileOnly)
.settings(ivyConfigurations += CompileOnly.hide)
You may also want to familiarize yourself with the provided
configuration. It's a standard Maven/Ivy config that means that the jar will be provide on the classpath at runtime (e.g. like the JDK, or a servlet container), but not at compile time.
val lib = Project("lib", file("lib")).dependsOn(macro % "compile-internal")
Just had this discussion last night...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With