Is there an SBT equivalent for Maven POM properties?

I am using the assembly definition file .sbt, and I have a number of dependent dependencies that have the same version number, for example:

libraryDependencies ++= Seq( "com.typesafe.akka" % "akka-actor" % "2.0.3", "com.typesafe.akka" % "akka-slf4j" % "2.0.3", ... "com.typesafe.akka" % "akka-testkit" % "2.0.3" % "test", ... ) 

I would like to be able to specify the version number in one place, as you could do in Maven with the properites element, i.e. you could specify the following in your pom:

 <propeties> <io.akka.version>2.0.3</io.akka.version> </properties> 

and then refer to this property later when declaring dependencies:

 <dependency> ... <version>${io.akka.version}</version> </dependency> 

Does anyone know if there is a similar approach in SBT?

+4
source share
2 answers

If you are using the full configuration (.scala file), just write plain scala code:

 val ioAkkaVersion = "2.0.3" libraryDependencies ++= Seq( "com.typesafe.akka" % "akka-actor" % ioAkkaVersion, "com.typesafe.akka" % "akka-slf4j" % ioAkkaVersion, ... "com.typesafe.akka" % "akka-testkit" % ioAkkaVersion % "test", ... ) 

For a .sbt configuration, this will look similar, but not so elegant:

 libraryDependencies ++= { val ioAkkaVersion = "2.0.3" Seq( "com.typesafe.akka" % "akka-actor" % ioAkkaVersion, "com.typesafe.akka" % "akka-slf4j" % ioAkkaVersion, ... "com.typesafe.akka" % "akka-testkit" % ioAkkaVersion % "test", ... ) } 
+11
source

Perhaps something like this?

 def akka(artifact: String) = "com.typesafe.akka" % ("akka-" + artifact) % "2.0.3" libraryDependencies ++= Seq(akka("actor"), akka("slf4j"), akka("testkit") % "test" ) 
+5
source

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


All Articles