Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a compile time only dependency in sbt

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 in the published POM.

The idea is to add a stub only library (OrangeExtensions) so that the project can be compiled on any platform not just OS X.

Is it possible like this somehow:

libraryDependencies += "com.yuvimasory" % "orange-extensions" % "1.3.0" % ???

?

like image 481
0__ Avatar asked Feb 02 '14 19:02

0__


People also ask

Which is the correct way to add dependencies in sbt file?

If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.

How do we specify library dependencies in sbt?

The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.

What is provided dependency in sbt?

The “provided” keyword indicates that the dependency is provided by the runtime, so there's no need to include it in the JAR file. When using sbt-assembly, we may encounter an error caused by the default deduplicate merge strategy. In most cases, this is caused by files in the META-INF directory.


1 Answers

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".

like image 147
gourlaysama Avatar answered Oct 09 '22 23:10

gourlaysama