Skip to content

feat(scanners): add support for simple Gradle version catalog aliases - #10

Open
Prabhat0770 wants to merge 1 commit into
ayushdoesdev:mainfrom
Prabhat0770:feat/gradle-version-catalog-support
Open

Prabhat0770 wants to merge 1 commit into
ayushdoesdev:mainfrom
Prabhat0770:feat/gradle-version-catalog-support

Conversation

@Prabhat0770

Copy link
Copy Markdown

Summary

This PR adds support for resolving simple Gradle version catalog aliases (gradle/libs.versions.toml) in build.gradle and build.gradle.kts files.

Context & Problem

Previously, JavaAnalyzer only extracted Gradle dependencies declared with literal group:artifact:version strings or map arguments. In modern Gradle projects utilizing version catalogs, dependencies declared as implementation(libs.androidx.core) or api(libs.some.lib) were missed during scans.

Changes

  1. Catalog Parser (_parse_version_catalog):

    • Parses [versions] and [libraries] from gradle/libs.versions.toml (and *.versions.toml).
    • Resolves inline versions (version = "..."), version references (version.ref = "..."), and module/group-name formats.
    • Maps normalized catalog alias variants (kebab-case, snake_case, dot-notation, and camelCase) to ensure consistent accessor lookup.
    • Unresolved version references and unsupported catalog tables remain safely unparsed (version = None) rather than guessed.
  2. Gradle Script Scanner (_parse_gradle):

    • Matches simple libs.<alias> references for all supported Gradle configurations (implementation, api, testImplementation, compileOnly, runtimeOnly, kapt, etc.).
    • Preserves existing literal dependency parsing alongside catalog alias resolution.
    • Leaves complex expressions (e.g. libs.foo.bar.get()) and unmapped aliases unresolved.
  3. Manifest Scanner (parse_dependencies):

    • Discovers gradle/libs.versions.toml and records it in files_found.
    • Passes parsed catalog data into _parse_gradle.
  4. Documentation:

    • Updated docs/languages.md to reflect catalog alias support and current limitations.

Testing

  • Added unit tests in backend/tests/scanners/test_java_analyzer.py:
    • test_parse_version_catalog_resolves_inline_and_ref_versions: Verifies inline version, version.ref, shorthand strings, and unresolved ref handling.
    • test_parse_gradle_resolves_catalog_aliases_and_supported_configurations: Verifies all configurations, dev markers, literal co-existence, and ignoring complex expressions.
    • test_parse_dependencies_with_gradle_version_catalog: End-to-end repository fixture scan with gradle/libs.versions.toml and build.gradle.kts.
  • Verified existing scanner test suite passes cleanly with zero regressions.
  • Ran ruff check (100% pass rate).

Closes #4

Support reading dependencies declared via Gradle version catalog aliases
(gradle/libs.versions.toml) in build.gradle and build.gradle.kts.

- Parse [versions] and [libraries] tables from version catalog TOML
- Resolve aliases defined via inline version strings, version.ref references,
  module coordinates, and group/name attributes
- Recognize libs.<alias> declarations across supported Gradle configurations
  (implementation, api, testImplementation, compileOnly, etc.)
- Keep unsupported expressions and unresolved references unparsed without guessing
- Add fixture-based tests and update docs/languages.md

Fixes ayushdoesdev#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for simple Gradle version catalog aliases

1 participant