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(manager/gradle): add support for Groovy and Kotlin maps #19127

Merged
merged 6 commits into from Nov 29, 2022

Conversation

Churro
Copy link
Collaborator

@Churro Churro commented Nov 27, 2022

Changes

Adds support for map collections up to 3rd-level nesting.

  • Support for Groovy maps, e.g.

    var versions = [
      graphqlJava          : "18.0",
      guava                : "com.google.guava:guava:31.1-jre",
      android: [
        buildTools         :  "30.0.3"
      ],
    ]
  • Support for Kotlin's mapOf collections, e.g.

    extra["deps"] = mapOf(
      "support" to mapOf(
        "appCompat" to "com.android.support:appcompat-v7:26.0.2",
        "junit" to mapOf(
          "jupiter" to "5.0.1"
        )
      )
    )

Implementation Notes

  • The parser code stacks the same matching code multiple times. This is done to propertly keep track of the hierarchy, e.g. deps -> deps.support -> deps.support.junit. The limitation of max. three levels was deliberately chosen to keep the code neat (while being still real-world friendly) but could be expanded, if needed.
  • Changes in handler.ts were made to match situations, where the map entry contains a string value that requires interpolation, e.g.
  ext.deps = [
    kotlinPlugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
  ]

kotlinPlugin is not added as a variable then as this would result in indirect variable references (varA: "someother$varB"). This is just an explanation, no limitation - this is the same behavior for simple, single variables already as well.

Context

Real-world examples that previously (= until this PR) didn't match at all:

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 tick 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 repository (= minimal reproduction from #13619):

Logs
"gradle": [
 {"packageFile": "settings.gradle", "datasource": "maven", "deps": []},
 {
   "packageFile": "build.gradle",
   "datasource": "maven",
   "deps": [
     {
       "depType": "plugin",
       "depName": "com.github.ben-manes.versions",
       "packageName": "com.github.ben-manes.versions:com.github.ben-manes.versions.gradle.plugin",
       "registryUrls": [
         "https://plugins.gradle.org/m2/",
         "https://repo.maven.apache.org/maven2",
         "https://repo.spring.io/plugins-release/"
       ],
       "commitMessageTopic": "plugin com.github.ben-manes.versions",
       "currentValue": "0.40.0",
       "managerData": {
         "fileReplacePosition": 230,
         "packageFile": "build.gradle"
       },
       "fileReplacePosition": 230,
       "depIndex": 0,
       "updates": [
         {
           "bucket": "non-major",
           "newVersion": "0.44.0",
           "newValue": "0.44.0",
           "releaseTimestamp": "2022-11-27T18:25:12.000Z",
           "newMajor": 0,
           "newMinor": 44,
           "updateType": "minor",
           "branchName": "renovate/java-java"
         }
       ],
       "warnings": [],
       "versioning": "gradle",
       "currentVersion": "0.40.0",
       "isSingleVersion": true,
       "fixedVersion": "0.40.0"
     },
     {
       "depType": "plugin",
       "depName": "com.github.spotbugs",
       "packageName": "com.github.spotbugs:com.github.spotbugs.gradle.plugin",
       "registryUrls": [
         "https://plugins.gradle.org/m2/",
         "https://repo.maven.apache.org/maven2",
         "https://repo.spring.io/plugins-release/"
       ],
       "commitMessageTopic": "plugin com.github.spotbugs",
       "currentValue": "5.0.3",
       "managerData": {
         "fileReplacePosition": 274,
         "packageFile": "build.gradle"
       },
       "fileReplacePosition": 274,
       "depIndex": 1,
       "updates": [
         {
           "bucket": "non-major",
           "newVersion": "5.0.13",
           "newValue": "5.0.13",
           "releaseTimestamp": "2022-11-27T16:08:15.000Z",
           "newMajor": 5,
           "newMinor": 0,
           "updateType": "patch",
           "branchName": "renovate/java-java"
         }
       ],
       "warnings": [],
       "versioning": "gradle",
       "currentVersion": "5.0.3",
       "isSingleVersion": true,
       "fixedVersion": "5.0.3"
     }
   ]
 },
 {
   "packageFile": "gradle/dependencies.gradle",
   "datasource": "maven",
   "deps": [
     {
       "depName": "com.github.spotbugs:spotbugs-annotations",
       "currentValue": "4.5.2",
       "managerData": {
         "fileReplacePosition": 181,
         "packageFile": "gradle/dependencies.gradle"
       },
       "groupName": "versions.spotbugs_annotations_version",
       "fileReplacePosition": 181,
       "registryUrls": [
         "https://plugins.gradle.org/m2/",
         "https://repo.maven.apache.org/maven2",
         "https://repo.spring.io/plugins-release/"
       ],
       "depType": "dependencies",
       "depIndex": 0,
       "updates": [
         {
           "bucket": "non-major",
           "newVersion": "4.7.3",
           "newValue": "4.7.3",
           "releaseTimestamp": "2022-10-17T05:06:37.000Z",
           "newMajor": 4,
           "newMinor": 7,
           "updateType": "minor",
           "branchName": "renovate/java-java"
         }
       ],
       "warnings": [],
       "versioning": "gradle",
       "sourceUrl": "https://github.com/spotbugs/spotbugs",
       "homepage": "https://spotbugs.github.io/",
       "currentVersion": "4.5.2",
       "isSingleVersion": true,
       "fixedVersion": "4.5.2"
     }
   ]
 }
],

@rarkins rarkins requested a review from viceice November 28, 2022 06:49
zharinov
zharinov previously approved these changes Nov 28, 2022
Co-authored-by: Sergei Zharinov <zharinov@users.noreply.github.com>
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

otherwise LGTM

lib/modules/manager/gradle/parser.spec.ts Outdated Show resolved Hide resolved
zharinov
zharinov previously approved these changes Nov 28, 2022
lib/modules/manager/gradle/parser.spec.ts Outdated Show resolved Hide resolved
lib/modules/manager/gradle/parser.spec.ts Outdated Show resolved Hide resolved
@rarkins rarkins enabled auto-merge (squash) November 29, 2022 06:50
@rarkins rarkins merged commit 84c51dc into renovatebot:main Nov 29, 2022
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 34.41.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants