Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Outline

Mongo Scala Driver

The driver-scala provides Scala-idiomatic wrappers for the Mongo Reactive Streams driver. It currently supports: Scala 2.11, Scala 2.12, Scala 2.13, and Scala 3.

Scala Versions

Supported Scala versions and their exact version numbers are defined in gradle.properties:

  • supportedScalaVersions — the list of supported Scala versions
  • defaultScalaVersion — the version used when no -PscalaVersion flag is provided (currently 2.13)

Build Configuration

The Scala source set configuration, compiler options, and dependency wiring are all handled in buildSrc/src/main/kotlin/project/scala.gradle.kts.

Library Dependencies

Scala library and test dependencies for each version are defined in gradle/libs.versions.toml. Look for entries prefixed with scala- in the [versions], [libraries], and [bundles] sections.

Directory Layout

Source code is organized into version-specific directories. Shared code goes in the common scala directory, while version-specific code goes in the appropriate directory:

src/main/
├── scala/          # Shared code (all Scala versions)
├── scala-2/        # Scala 2 only (2.11, 2.12 and 2.13)
├── scala-2.13/     # Scala 2.13 only
├── scala-2.13-/    # Scala 2.12 & 2.11
├── scala-3/        # Scala 3 only

Test code also supports the same directory structure. The source sets for each Scala version are configured in buildSrc/src/main/kotlin/project/scala.gradle.kts. When adding new code, place it in the most general directory that applies. Only use a version-specific directory when the code requires syntax or APIs unique to that version.

Code Formatting (Spotless)

Spotless defaults to Scala 2.13 formatting rules for all code apart from Scala 3 code.

For Scala 3 specific code, the bson-scala/build.gradle.kts shows how to configure Spotless to use a Scala 3 scalafmt config. It targets only files in **/scala-3/** and uses a separate config/scala/scalafmt-3.conf:

if (scalaVersion.equals("3")) {
    spotless {
        scala {
            clearSteps()
            target("**/scala-3/**")
            scalafmt("3.10.7").configFile(rootProject.file("config/scala/scalafmt-3.conf"))
        }
    }
}

Use this pattern in other build.gradle.kts files if they also contain Scala 3 specific code.

Testing

By default, tests run against Scala 2.13. To test against a specific Scala version, pass the -PscalaVersion flag:

# Test driver-scala with Scala 3
./gradlew :driver-scala:scalaCheck -PscalaVersion=3

# Test driver-scala with Scala 2.12
./gradlew :driver-scala:scalaCheck -PscalaVersion=2.12

# Test driver-scala with the default (2.13) against Java 8
./gradlew :driver-scala:scalaCheck -PjavaVersion=8
Morty Proxy This is a proxified and sanitized view of the page, visit original site.