Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gradle/manager): add support for Kotlin objects in buildSrc files #21892

Merged
merged 4 commits into from May 10, 2023

Conversation

Churro
Copy link
Collaborator

@Churro Churro commented Apr 29, 2023

Changes

  • Adds functionality to parse variables and dependencies in Kotlin's object { ... } declarations.
  • This PR enables out-of-the-box parsing of *.kt files in the buildSrc folder
  • The gradle parser now also supports local variables. If used in within an understood (object { ... }, mapOf, ...) hierarchy, renovate preferrably resolve variables in the local scope

Example:

object Foo {
  object Versions {
    const val nanoHttp = "2.3.1"
  }
  const val nanoHttp = "org.nanohttpd:nanohttpd-webserver:${Versions.nanoHttp}"
}

Implementation Notes

  • Kotlin source files are parsed twice since objects may cross-reference each other in different files
    • The 1st pass extracts all variables + resolvable dependencies. The 2nd pass is needed for dependencies that rely on version definitions from different files (maybe even residing in subfolders)
    • The gradle manager does dep deduplication in the post processing of extractAllPackageFiles() in extract.ts, so ultimately deps are extracted only once
  • Variables extracted from Kotlin files are considered global, i.e., added to the / scope. This is needed because a variable X defined in buildSrc/some/file.kt can be referenced from any .gradle or .gradle.kts build file.

Context

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

Test scenarios

  1. Simple, standard case
  2. Variables defined in object are then reused in regular .gradle / .gradle.kts files
  3. Variable with version is defined after dependencies or in a different file than the dependency itself

@AlvaroZapp
Copy link

Hi! I need this feature, do you know when it will be released?

zharinov
zharinov previously approved these changes May 10, 2023
Copy link
Collaborator

@zharinov zharinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except one suggestion

lib/modules/manager/gradle/parser/common.ts Outdated Show resolved Hide resolved
@Churro Churro requested a review from zharinov May 10, 2023 18:51
@rarkins rarkins enabled auto-merge May 10, 2023 19:13
@rarkins rarkins added this pull request to the merge queue May 10, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 10, 2023
@rarkins rarkins added this pull request to the merge queue May 10, 2023
Merged via the queue into renovatebot:main with commit eec46d1 May 10, 2023
11 checks passed
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 35.78.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@hoc081098
Copy link

Nice 👍 . I just noticed this when renovate bot creating many PRs 😁

@AlvaroZapp
Copy link

Hi!

I'm trying running renovate and I'm experiencing a problem with lists, it's not recognizing them:

val core = mutableListOf<String>().apply {
        add("com.google.android.material:material:$support_material")
        add("androidx.lifecycle:lifecycle-reactivestreams-ktx:$vlifecycle")
        add("androidx.lifecycle:lifecycle-livedata-ktx:$vlifecycle")
        add("androidx.lifecycle:lifecycle-runtime-ktx:$vlifecycle")
        add("androidx.core:core-ktx:$ktx_core")
}
dependencies {
    CoreConstant.core.forEach { api(it) }
}

mjunker pushed a commit to mjunker/renovate that referenced this pull request May 17, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
6 participants