Add a compile time only dependency in sbt

前端 未结 1 809
北荒
北荒 2020-12-14 02:59

I would like to add a dependency to an sbt project which is only used for compilation. Neither should it be on the runtime class path, nor should it be visible in any form i

相关标签:
1条回答
  • 2020-12-14 03:23

    You can create a custom dependency configuration for this (actually, this is getting so common when you use private macros in your project, I wish SBT provided one).

    In build.sbt:

    // a 'compileonly' configuation
    ivyConfigurations += config("compileonly").hide
    
    // some compileonly dependency
    libraryDependencies += "commons-io" % "commons-io" % "2.4" % "compileonly"
    
    // appending everything from 'compileonly' to unmanagedClasspath
    unmanagedClasspath in Compile ++= 
      update.value.select(configurationFilter("compileonly"))
    

    That dependency will not appear in the pom.xml generated by publish and friends.

    There almost is such a configuration available: the provided configuration. Except that provided ends up in the pom.xml as a dependency with provided scope. Also, provided means "the runtime itself provides this at runtime", not "this is not needed at runtime".

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