Add a compile time only sub-project dependency in sbt

后端 未结 2 2083
情深已故
情深已故 2021-02-06 10:19

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 classpa

相关标签:
2条回答
  • 2021-02-06 11:00
    val lib = Project("lib", file("lib")).dependsOn(macro % "compile-internal") 
    

    Just had this discussion last night...

    0 讨论(0)
  • 2021-02-06 11:12

    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.

    0 讨论(0)
提交回复
热议问题