Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sbt/sbt/llms.txt

Use this file to discover all available pages before exploring further.

The JvmPlugin provides core functionality for building JVM-based projects. It includes tasks for compilation, running, testing, and managing classpaths. This plugin is automatically enabled for any project that can use Ivy for dependency management.

Activation

Overview

JvmPlugin is the foundation for JVM project builds in sbt. It provides:
  • Compilation: Scala and Java source compilation
  • Execution: Running main classes and forked processes
  • Testing: Test discovery, execution, and frameworks
  • Classpaths: Managed and unmanaged classpath construction
  • Configurations: Standard Compile, Test, and Runtime configurations

Configurations

JvmPlugin defines standard configurations via Configurations.default:
  • Compile: Main source code and production dependencies
  • Test: Test source code and test dependencies
  • Runtime: Dependencies needed at runtime
  • Provided: Compile-time only dependencies
  • Optional: Optional dependencies
  • IntegrationTest: Integration test configuration

Global Settings

Provided through globalJvmCore:

Scala Configuration

SettingTypeDefaultDescription
scalaOrganizationString"org.scala-lang"Organization for Scala artifacts
scalaArtifactsSeq[String]Standard artifactsScala artifact names
autoScalaLibraryBooleantrueAutomatically add Scala library dependency
managedScalaInstanceBooleantrueUse managed Scala instance
scalaHomeOption[File]NoneOverride Scala location
crossPathsBooleantrueEnable cross-version source paths

Java Configuration

SettingTypeDefaultDescription
javaHomeOption[File]NoneOverride Java home location
discoveredJavaHomesMap[String, File]Auto-discoveredAvailable Java installations
javaHomesMap[String, File]Empty mapUser-specified Java homes
fullJavaHomesMap[String, File]MergedAll available Java homes
javaOptionsSeq[String]NilJVM options for forked processes

Compilation

SettingTypeDefaultDescription
compilerCacheCompilerCacheFresh cacheCaches Scala/Java compilers
autoCompilerPluginsBooleantrueAutomatically add compiler plugins
allowMachinePathBooleantrueAllow machine-specific paths in output
reportAbsolutePathBooleantrueReport absolute paths in errors

Source Management

SettingTypeDefaultDescription
sourcesInBaseBooleantrueInclude .scala files in base directory
unmanagedSources / includeFilterFileFilter"*.java" | "*.scala"Filter for source files
sourcePositionMappersSeq[PositionMapper]NilMap source positions in errors

Testing

SettingTypeDefaultDescription
testForkedParallelBooleantrueRun forked tests in parallel
testForkedParallelismOption[Int]NoneMax parallel test executions

ClassPath & JARs

SettingTypeDefaultDescription
unmanagedJars / includeFilterFileFilterJARs, SOs, DLLs, etc.Filter for unmanaged JARs
unmanagedResources / includeFilterFileFilterAllPassFilterFilter for resources

Background Jobs

SettingTypeDefaultDescription
bgListTask[Seq[JobHandle]]Current jobsList running background jobs
bgStopInputTask[Unit]Stop implementationStop background job(s)
bgWaitForInputTask[Unit]Wait implementationWait for background job
bgCopyClasspathBooleantrueCopy classpath for background jobs

ClassLoader Management

SettingTypeDefaultDescription
closeClassLoadersBooleanFrom system propertyClose class loaders after tasks
allowZombieClassLoadersBooleantrueAllow unreferenced class loaders

API Documentation

SettingTypeDefaultDescription
autoAPIMappingsBooleanfalseAutomatically generate API mappings
apiMappingsMap[File, URL]Empty mapMap JARs to API documentation URLs
apiURLOption[URL]NoneAPI documentation URL
releaseNotesURLOption[URL]NoneRelease notes URL

Packaging

SettingTypeDefaultDescription
packageTimestampLongPlatform-dependentTimestamp for reproducible packages
packageSrc / artifactClassifierOption[String]Some("sources")Classifier for source JARs
packageDoc / artifactClassifierOption[String]Some("javadoc")Classifier for documentation JARs

Plugin Development

SettingTypeDefaultDescription
sbtPluginBooleanfalseIs this an sbt plugin project?
isMetaBuildBooleanfalseIs this a meta-build project?
reresolveSbtArtifactsBooleanfalseRe-resolve sbt artifacts on reload

Incremental Compilation

SettingTypeDefaultDescription
extraIncOptionsSeq[(String, String)]Java class versionExtra options for incremental compiler

File Conversion

SettingTypeDefaultDescription
rootPathsMap[String, Path]Standard rootsRoot paths for file conversion
fileConverterFileConverterMappedFileConverterConverts between absolute and virtual paths

Trace Levels

SettingTypeDefaultDescription
run / traceLevelInt0Trace level for run task
runMain / traceLevelInt0Trace level for runMain
bgRun / traceLevelInt0Trace level for background runs
console / traceLevelIntInt.MaxValueTrace level for console

Build Settings

Provided through buildLevelJvmSettings:

Project Settings

JvmPlugin combines multiple setting groups:

Source Paths

From paths:
SettingTypeDefaultDescription
sourceDirectoryFilebaseDirectory / "src"Root source directory
sourceManagedFiletarget / "src_managed"Generated source directory
resourceManagedFiletarget / "resource_managed"Generated resource directory
historyPathOption[File]Output directory .historyCommand history file location

Compilation Tasks

From compileBase:
SettingTypeDefaultDescription
scalaInstanceTask[ScalaInstance]Auto-configuredScala compiler instance
scalaInstanceConfigTask[ScalaInstanceConfig]Auto-configuredScala instance configuration
scalaCompilerBridgeJarsTask[Seq[File]]Auto-resolvedCompiler bridge JARs
scalaCompilerBridgeSourceModuleIDDefault bridgeCompiler bridge module dependency
classpathOptionsClasspathOptionsAuto-configuredClasspath filtering options
cleanTask[Unit]Clean implementationClears compilation artifacts
crossTargetFiletargetCross-version target directory
crossVersionCrossVersionBased on crossPathsCross-version strategy
crossSbtVersionsSeq[String]Current sbt versionsbt versions for cross-building plugins

Running & Execution

From runnerSettings:
SettingTypeDefaultDescription
runInputTask[Unit]Main class runnerRun a main class
runMainInputTask[Unit]Named main runnerRun a specific main class
runnerTask[ScalaRun]Runner instanceRuns Scala/Java code

Base Tasks

From baseTasks:
SettingTypeDefaultDescription
cleanTask[Unit]Clean files taskDelete build outputs
cleanFilesSeq[File]ComputedFiles to delete on clean
updateTask[UpdateReport]From IvyPluginResolve and retrieve dependencies
consoleTask[Unit]Scala REPLStart an interactive Scala console
consoleQuickTask[Unit]Quick consoleConsole without compiling dependencies
consoleProjectTask[Unit]Project consoleConsole with project classes

Configuration-Specific Settings

From defaultConfigs, applied to Compile, Test, and Runtime:

Compile Configuration

SettingTypeDescription
compileTask[CompileAnalysis]Compile sources
compileIncrementalTask[CompileResult]Incremental compilation
javacOptionsSeq[String]Java compiler options
scalacOptionsSeq[String]Scala compiler options
sourcesTask[Seq[File]]All source files
unmanagedSourcesTask[Seq[File]]Unmanaged sources
managedSourcesTask[Seq[File]]Generated sources
sourceDirectoriesSeq[File]Source directories
scalaSourceFileScala source directory
javaSource`File“Java source directory
resourceDirectoryFileResource directory
resourcesTask[Seq[File]]All resource files
classDirectoryFileCompiled class output
productsTask[Seq[File]]Compilation products
fullClasspathTask[Classpath]Complete classpath
internalDependencyClasspathTask[Classpath]Inter-project dependencies
externalDependencyClasspathTask[Classpath]External dependencies
unmanagedClasspathTask[Classpath]Unmanaged JARs
managedClasspathTask[Classpath]Managed dependencies
exportedProductsTask[Classpath]Products exported to dependents
copyResourcesTask[Seq[(File, File)]]Copy resources to output
sourceGeneratorsSeq[Task[Seq[File]]]Tasks generating sources
resourceGeneratorsSeq[Task[Seq[File]]]Tasks generating resources
mainClassOption[String]Main class to run
discoveredMainClassesTask[Seq[String]]All discovered main classes
selectMainClassTask[Option[String]]Select which main class to run

Test Configuration

Includes all compile settings plus:
SettingTypeDescription
testTask[Unit]Run all tests
testOnlyInputTask[Unit]Run specific tests by name
testQuickTask[Unit]Run tests affected by changes
testSelectedInputTask[Unit]Interactively select tests
testFrameworksSeq[TestFramework]Available test frameworks
testListenersSeq[TestReportListener]Test result listeners
testOptionsSeq[TestOption]Test execution options
testLoaderTask[ClassLoader]Class loader for tests
loadedTestFrameworksTask[Map[TestFramework, Framework]]Loaded framework instances
definedTestsTask[Seq[TestDefinition]]Discovered test definitions
definedTestNamesTask[Seq[String]]Test names
executeTestsTask[Tests.Output]Execute test suites
testResultLoggerTestResultLoggerLogger for test results

Runtime Configuration

Includes classpath settings for runtime execution.

Usage Examples

Configure Java Version

javacOptions ++= Seq("-source", "11", "-target", "11")

Add Scala Compiler Options

scalacOptions ++= Seq(
  "-deprecation",
  "-feature",
  "-Xfatal-warnings"
)

Set Main Class

Compile / mainClass := Some("com.example.Main")

Configure Test Parallelism

Test / testForkedParallelism := Some(4)

Add Unmanaged JAR Directory

Compile / unmanagedJars := (baseDirectory.value / "lib" ** "*.jar").classpath

Disable Source in Base Directory

sourcesInBase := false

Fork JVM for Running

fork := true
javaOptions ++= Seq("-Xmx2G", "-Xms512M")

Add Custom Test Framework

Test / testFrameworks += new TestFramework("com.example.CustomFramework")

Configure API Mappings

autoAPIMappings := true
apiURL := Some(url("https://www.scala-lang.org/api/current/"))

Configuration Scoping

Most JvmPlugin settings are configuration-scoped. Access them with:
// Compile configuration
Compile / sourceDirectory
Compile / compile
Compile / run

// Test configuration  
Test / sourceDirectory
Test / test
Test / testOnly

// Runtime configuration
Runtime / fullClasspath
JvmPlugin is essential for all JVM-based sbt projects. It works together with IvyPlugin to provide complete dependency management and build capabilities for Scala and Java projects.
  • CorePlugin - Provides fundamental build infrastructure
  • IvyPlugin - Required dependency, provides Ivy dependency resolution
  • SbtPlugin - Extends JvmPlugin for sbt plugin development

Source

JvmPlugin implementation: sbt.plugins.JvmPlugin