How to Launch a Scan on Java/Scala/Kotlin
Optimize SCA scanning by using Gradle lockfiles and pinned versions for Java, Scala, or Kotlin builds.
For Gradle-based projects in Java, Scala, or Kotlin, generating a gradle.lockfile
ensures consistent dependencies that CybeDefend can accurately scan. SBT-based Scala projects can also pin versions in .sbt.lock
or a centralized method.
Gradle Lockfiles
-
Enable Gradle Locking
You can enable dependency locking in one of two ways:Option A: In your
gradle.properties
, set:Option B: Modify your
build.gradle
file to add:Or for Kotlin DSL projects (
build.gradle.kts
): -
Generate Lockfiles
Run one of these commands:or
This creates lockfiles in the
gradle/dependency-locks
directory. -
Commit
Check in the lockfiles so that your entire team and CybeDefend sees fixed dependency versions.
Why You Should Use Lockfiles
Using a lockfile is critical for secure and predictable builds. A lockfile contains a fixed version and a hash for each dependency and sub-dependency in your project.
- Supply Chain Protection
Lockfiles prevent malicious package injections. This is crucial as supply chain attacks are rising. - Predictable Builds
Everyone uses the exact same package versions, avoiding “it works on my machine” inconsistencies. - Performance Gains
With dependency versions locked, build tools skip the usual resolution step, making builds faster.
Lockfiles are never edited manually. They’re generated and updated by your package manager and committed to your repository, ensuring consistent environments for all teammates.
SBT Lock for Scala
-
Add the sbt-lock Plugin
In yourproject/plugins.sbt
, add: -
Generate the Lockfile
Run:This creates a
build.sbt.lock
ordependencies.sbt.lock
file. -
Commit the Lockfile
Add this file to your repository to maintain pinned Scala library versions.
Supported Files
Lang | File Examples |
---|---|
Java | gradle.lockfile , pom.xml , .jar , .war , .ear |
Scala | build.sbt , plugins.sbt , .sbt.lock , dependencies.scala , .scala |
Kotlin | gradle.lockfile , .kts files (Gradle Kotlin DSL) |
Some older build tools or frameworks may require additional steps. The primary goal is to produce a stable lock or pinned version set for each submodule.
For multi-module Gradle projects, run ./gradlew :module:dependencies —write-locks
for each module to ensure all dependencies are properly locked.