Skip to content

Add config file class for Kotlin Gradle `build.gradle.kts`

Leaminn Ma requested to merge add-kotlin-gradle-config-file-class into master

What does this MR do and why?

Background

The Repository X-Ray is a tool that searches for dependency manager configuration or lock files and then extracts a list of libraries from the content.

In #474306 (comment 2025085630), we decided to migrate the Repository X-Ray functionality into the GitLab Rails monolith. This gives us two main benefits: (i) it will eventually allow us to run the service outside of the CI pipeline, and (ii) we can maintain the parsing logic centrally so that other domains can utilize it.

Base MR

In !162313 (merged), we introduced the ConfigFiles::Base class where the intention is for each dependency manager config file type to be represented by a child class. The child class contains the parsing logic to extract a list of libraries and their versions from the file content.

This MR

In this MR, we introduce the KotlinGradle config file class that parses build.gradle.kts. It inherits from JavaGradle which has been refactored to accommodate both languages.

For references to the existing parsing logic in the Repository X-Ray repo, see:

Resolves part of #476177 (closed).

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Create a new blank project and add the following file to the repo:

subdir/build.gradle.kts:

buildscript {
    repositories {
        google()
        mavenCentral()
    }
}

val arcgisVersion = "4.5.0"

dependencies { // Comment
    implementation("org.codehaus.groovy:groovy:3.+")
    testImplementation("com.google.guava:guava:29.0.1") // Inline comment

    implementation(project(":utils"))
    runtimeOnly(files("libs/a.jar", "libs/b.jar"))

    // String interpolation is not currently supported
    implementation("com.esri.arcgisruntime:arcgis-java:$arcgisVersion")
}

java {
    withSourcesJar()
}
  1. Run the service in the Rails console:
project = Project.last # Should be the project you created in Step 1

response = Ai::RepositoryXray::ScanDependenciesService.new(project).execute

Screenshot_2024-09-11_at_6.24.46_PM

  1. Observe that the X-ray report for the valid config file (Gemfile.lock) is recorded:
project.reload.xray_reports

Screenshot_2024-09-11_at_6.25.24_PM

Related to #476177 (closed)

Edited by Leaminn Ma

Merge request reports

Loading