Gradle
Getting Started
Configuring bloop in your Gradle projects will speed up your Scala development significantly. It is highly recommended to use Bloop in Gradle because Gradle has a pretty long development cycle and it takes a long time to do basic build operations such as compilation or running an application.
The Gradle plugin lives in its own repository at scalacenter/gradle-bloop. Please do report any issues with the Gradle integration there!
Learn how to get set up by following the instructions below.
Requirements
- For Scala 2: at least Gradle
v5.0
- For Scala 3: at least Gradle
v7.3
- For Android: at least Gradle
v6.1.1
- Latest (tested) supported version is
v7.5
Install the plugin
Add bloop to your build.gradle
with:
buildscript {
repositories {
// Add here whatever repositories you're already using
mavenCentral()
}
dependencies {
classpath 'ch.epfl.scala:gradle-bloop_2.12:1.6.2'
}
}
Then, enable bloop in all your Gradle projects with:
allprojects {
// test is for compatibility with Metals import
if (!plugins.hasPlugin("bloop")) {
apply plugin: "bloop"
}
}
For a more advanced configuration, read the Plugin Configuration below.
Export your build
The gradle command bloopInstall
exports your gradle build to bloop.
The gradle plugin generates a configuration file per every source set in your build definition. By default, there are two source sets: that of compile and that of test. Bloop will skip config file generation for those projects that are not either Java or Scala.
$ ./gradlew bloopInstall
For example, a build with a single Scala project foo
generates two configuration files by default:
$ ./gradlew bloopInstall
(...)
Generated '/disk/foo/.bloop/foo.json'.
Generated '/disk/foo/.bloop/foo-test.json'.
where:
foo
comes from the compile source set; and,foo-test
comes from the test source set and depends onfoo
If you have applied Bloop to all the projects in your build but some of your projects can't be understood by Bloop (for example, they are not Java or Scala projects), you will see the following log:
Ignoring 'bloopInstall' on non-Scala and non-Java project '$NON_JVM_PROJECT'
You can safely ignore such messsages.
Verify installation and export
Remember that the build server must be running in the background, as suggested by the Setup page.
Verify your installation by running bloop projects
in the root of the gradle workspace directory.
$ bloop projects
foo
foo-test
If the results of bloop projects
is empty, check that:
- You are running the command-line invocation in the root base directory (e.g.
/disk/foo
). - The gradle build export process completed successfully.
- The
.bloop/
configuration directory contains bloop configuration files.
Debug the export with
./gradlew bloopInstall -Si
.
If you suspect bloop is loading the configuration files from somewhere else, run --verbose
:
$ bloop projects --verbose
[D] Projects loaded from '/my-project/.bloop':
foo
foo-test
Here's a list of bloop commands you can run next to start playing with bloop:
bloop compile --help
: shows the help section for compile.bloop compile foo-test
: compiles foo'ssrc/main
andsrc/test
.bloop test foo-test -w
: runs foo tests repeatedly with file watching enabled.
Next steps after installation
Use an IDE such as Metals or IntelliJ to write code or play with the CLI if you want to explore what CLI options are available.
If you need help, you can always come over our Discord channel.
Plugin Configuration
Enable bloop plugin selectively
If your build only has a handful of Scala/Java projects and you don't want to enable Bloop in all projects by default, you can selectively enable bloop with:
if (!plugins.hasPlugin("bloop")) {
apply plugin: "bloop"
}