kypeli / sversion

Inspired by PHP's compare_version() function, this library lets you compare two version strings with ease in Scala.


Build Status

sversion is a Scala library that lets you easily compare version strings

Inspired by PHP's version_compare this library lets you to compare two version strings with regular comparison operators in Scala.

  • The version string is expected to be separated by ., _ or - characters.
  • The version string can contain additional characters such as RC.
  • Different version lengths are taken into account.
  • Succeeding 0s are omitted.
  • All comparison operators are supported (>, >=, <, <= and ==)


For Scala 2.11 with sbt, add the following dependency to your build.sbt file:

libraryDependencies ++= Seq(
// ...
  "com.github.kypeli" %% "sversion" % "1.1.1"
// ...


Normal version strings.

import com.github.sversion.Version

Version("1.2") > Version("1.1")  // true

Version("1.2.1") > Version("1.1.2")  // true

Version("1.1.1") == Version("1.1.1")  // true

Version strings of different length.

import com.github.sversion.Version

Version("1.1.1") > Version("1.1")  // true

Version("1.1.0") == Version("1.1")  // true

Version strings with additional characters.

import com.github.sversion.Version

Version("1.1-RC2") > Version("1.1-RC1")  // true

Version("1.1-RC1") > Version("1.1")  // true

Implicit conversions

Implicit conversions are also possible directly from Strings.

import com.github.sversion.Version
import com.github.sversion.utils.Implicit
import Implicit._

val v1: Version = "1.2.0"
val v2: Version = "1.1.0"

v1 > v2  // true

Thank you

This code is being sponsored by Futurice Spice Program


Apache 2.0