Scala
Scala is a general-purpose and scalable programming language widely used by developers. Endor Labs supports the scanning and monitoring of Scala projects managed by either the interactive build tool sbt or Gradle.
Using Endor Labs, application security engineers and developers can:
- Scan their software for potential security issues and violations of organizational policy.
- Prioritize vulnerabilities in the context of their applications.
- Understand the relationships between software components in their applications.
System specifications for scan
Make sure that your system has a minimum 8-core processor with 32 GB RAM to successfully scan Scala projects.
Software prerequisites
- Install JDK versions between 11 and 25.
- For JDK 8, see Scan projects on JDK version 8.
- Make sure your repository includes one or more files with
.scalaor.scextension. - Install sbt version 1.4 or higher if your project uses sbt.
- For sbt versions lower than 1.4, install the sbt-dependency-graph plugin, which is included by default in sbt 1.4 and later.
- Ensure that the
project/build.propertiesfile specifies the required sbt version.
- Install Gradle build system version 6.0.0 and higher, if your project uses Gradle.
- To support lower versions of Gradle, see Scan projects on older Gradle versions.
- Your repository must include the appropriate build manifest file:
build.sbtfor sbt projects.build.gradleorbuild.gradle.ktsfor Gradle projects.
Build Scala projects
Before initiating a scan with Endor Labs, ensure that your Scala projects are built successfully. Additionally, ensure that the packages are downloaded into local package caches and build artifacts are present in their standard locations. Follow the guidelines to build projects using sbt or Gradle.
Use Gradle
To analyze your software built with Gradle, you must successfully build the software. To perform a quick scan, locate the dependencies in the local package manager cache. Ensure that the standard $GRADLE_USER_HOME/caches or /User/<username>/.gradle/caches exists and contains successfully downloaded dependencies. To perform a deep scan, generate the target artifact on the file system as well.
Use the flag ENDOR_SCAN_ENABLE_SCALA_GRADLE to build Scala projects using Gradle.
export ENDOR_SCAN_ENABLE_SCALA_GRADLE=true
To build your project with Gradle, use the following procedure:
-
To run a scan against a custom configuration, specify the Gradle configuration by setting an environment variable.
export endorGradleScalaConfiguration="<configuration>"When no configuration is provided,
runtimeClasspathis used by default.If neither the user-specified nor the default configuration exists in the project, the system falls back to the following configurations, in order:
runtimeClasspathruntimecompileClasspathcompile
If the listed configurations are not found in the project, the system selects the first available configuration in alphabetical order.
-
Ensure that you can resolve the dependencies for your project without errors by running the following command:
For Gradle wrapper:
./gradlew dependenciesFor Gradle:
gradle dependencies -
Run
./gradlew assembleorgradle assembleto resolve dependencies and to create an artifact that may be used for deep analysis.
Override subproject level configuration
In a multi-build project, if you set the environment variable endorGradleScalaConfiguration=[GlobalConfiguration], the specified configuration is used for dependency resolution across all projects and subprojects in the hierarchy below.
\--- Project ':samples'
+--- Project ':samples:compare'
+--- Project ':samples:crawler'
+--- Project ':samples:guide'
+--- Project ':samples:simple-client'
+--- Project ':samples:slack'
+--- Project ':samples:static-server'
+--- Project ':samples:tlssurvey'
\--- Project ':samples:unixdomainsockets'
To override the configuration only for the :samples:crawler and :samples:guide subprojects, follow these steps:
-
Navigate to the root workspace, where you execute
endorctl scan, and run./gradlew projectsto list all projects and their names. -
Run the following command at the root of the workspace:
echo ":samples:crawler=testRuntimeClasspath,:samples:guide=macroBenchMarkClasspath" >> .endorpropertiesThis creates a new file named
.endorpropertiesin your root directory. This enables different configurations for the specified subprojects in the file. -
Run
endorctl scan.
At this point, all other projects will adhere to the GlobalConfiguration. However, the :samples:crawler subproject will use the testRuntimeClasspath configuration, and the :samples:guide subproject will use the macroBenchMarkClasspath configuration.
Configure private Gradle package repositories
Endor Labs supports fetching and scanning dependencies from private Gradle package registries. Endor Labs will fetch resources from authenticated endpoints and perform the scan, allowing you to view the resolved dependencies and findings. See Gradle package manager integrations for more information on configuring private registries.
Use sbt
To analyze your software built with sbt, you must successfully build the software.
- The standard
.sbtcache must exist and contain all required dependencies for both quick and deep scans. - For deep scans, the build artifact must exist on the filesystem.
- Make sure
sbt dependencyTreeruns successfully inside the project directory.
Quick scan
Run a quick scan to rapidly assess your dependencies using only the compiled code and cached packages.
-
Run the following commands to build the project successfully. Ensure your repository has a
build.sbtfile.sbt compilesbt projects
Deep scan
Run a deep scan to enable advanced static analysis features by generating packaged artifacts.
-
Run the following commands to build the project successfully. Ensure your repository has a
build.sbtfile.sbt packagesbt projects
Run a scan
Run an endorctl scan to get visibility into your software composition and resolve dependencies.
endorctl scan
You can perform the scan from within the root directory of the Git project repository and save the local results to a results.json file. The results and related analysis information are available on the Endor Labs user interface.
endorctl scan -o json | tee /path/to/results.json
Sign in to the Endor Labs user interface, click Projects on the left sidebar, and find your project to review its results.
Note
If your project includes both sbt and Gradle build systems, Endor Labs scans your project using only one build system to avoid scanning the same packages multiple times. When both are present, Gradle has higher priority for dependency resolution.Understand the scan process
Endor Labs scans Scala projects by executing sbt plugins and inspecting the build.sbt file to retrieve information about direct and transitive dependencies.
- The
build.sbtfile is a configuration file used in Scala projects with sbt to define project settings, dependencies, and build tasks. This file provides the necessary configuration and instructions to sbt on resolving and managing project dependencies. - The sbt dependency graph plugin visualizes the dependencies between modules in a Scala project.
- For packages built using Gradle, it uses Gradle and Gradle wrapper files to build packages and resolve dependencies.
- Endor Labs supports EAR, JAR, RAR, and WAR files.
Endor Labs analyzes information from both these methods to determine different components, binary files, manifest files, images, and more in the Scala codebase. It presents finding policy violations, identifies dependencies, and resolves them.
Using Endor Labs, users can gain significant insights into the structure and relationships of their Scala project’s dependencies. This aids in managing dependencies effectively, identifying potential issues, and ensuring a well-organized and maintainable codebase.
How Endor Labs performs static analysis on the code
Endor Labs performs static analysis based on the following factors:
- Call graphs are created for your package. These are then combined with the call graphs of the dependencies in your dependency tree to form a comprehensive call graph for the entire project.
- Endor Labs performs an inside-out analysis of the software to determine the reachability of dependencies in your project.
- The static analysis time may vary depending on the number of dependencies in the package and the number of packages in the project.
Known limitations
Endor Labs does not currently support software composition analysis for Scala on Microsoft Windows operating systems.
Troubleshoot errors
Here are a few error scenarios that you can check for and attempt to resolve them.
- Host system check failure errors: These errors occur if:
- sbt is not installed or present in the path variable. Install sbt 1.4 or higher versions and try again.
- The sbt version mentioned in the project or the
build.propertiesfile is lower than 1.4 and thesbt-dependency-graphplug-in is not installed. Install thesbt-dependency-graphplug-in and try again. - Java is not installed or not present in the PATH environment variable. Install Java and try again. See Java documentation for more information.
- The installed version of Java is lower than the required version. Install JDK versions between 11 and 25 and try again.
- Java is installed but sbt or Gradle is not installed. In such cases, the dependency resolution may not be complete.
- Dependency graph errors: Scala by default imports
MiniDependencyTreePlugin, which is a mini version of thesbt-dependency-graphplugin and supports only thedependencyTreecommand. To get complete features of thesbt-dependency-graphplugin, addDependencyTreePluginto yourproject/plugins.sbtfile and run the scan again. See Scala documentation for details.
Feedback
Was this page helpful?
Thanks for the feedback. Write to us at support@endor.ai to tell us more.
Thanks for the feedback. Write to us at support@endor.ai to tell us more.