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

Don't consider references to catalogs in buildfiles #6878

Merged
merged 1 commit into from
Mar 22, 2023

Conversation

deivid-rodriguez
Copy link
Contributor

Fixes #6863.

Trully fixing this (as in, actually create correct PRs) was out of scope for the first MVP for Gradle Version Catalogs, and I don't want to continue with the business of parsing Kotlin/Java code in Ruby. The way to go for us is probably to leverage #1164.

So the way I approached this is to just avoid creating an incorrect PR by fixing the underlying bug that caused that.

Explanation of the fix:

We do support some bare version replacements in build files, for example,

val helmVersion = "1.6.0"
id("org.unbroken-dome.helm") version helmVersion apply false

What the code used to do was checking whether the version parsed was all "word characters" or not.

If all word characters, then it's considered a property name, a value for the property is looked up, and if a value cannot be found, then the dependency is ignored.

If not all word characters, then it's considered a version number, and the dependency is only ignored if the version number is not valid.

In this case, libs.versions.<ref> includes dots, which are not word characters, so it does not match the regexp to be considered a property reference. As a consequence, it's considered a version number, and accepted as a dependency because libs.versions.<ref> is actually a valid maven version number.

I could've tweaked the regexp to accept dots for property names, but I think it's a better criteria to check whether to matched value is quoted. If it is, it's a version number, otherwise it's a property.

So I implemented that.

Copy link
Member

@Nishnha Nishnha left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation!

I also checked that the VSN_PART regex captures literal versions and dynamic versions as expected

Screenshot 2023-03-21 at 2 26 56 PM

@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/gradle-incorrect-pr branch from c968344 to 071bbba Compare March 22, 2023 16:00
We do support some bare version replacements in build files, for
example,

```
val helmVersion = "1.6.0"
id("org.unbroken-dome.helm") version helmVersion apply false
```

What the code use to do was checking whether the version parsed was all
"word characters" or not.

If all word characters, then it's considered a property name, a value
for the property is looked up, and if a value cannot be found, then the
dependency is ignored.

If not all word characters, then it's considered a version number, and
the dependency is only ignored if the version number is not valid.

In this case, `libs.versions.<ref>` includes dots, which are not word
characters, so it does not match the regexp to be considered a property
reference. As a consequence, it's considered a version number, and
accepted as a dependency because `libs.versions.<ref>` is actually a
valid maven version number.

I could've tweaked the regexp to accept dots for property names, but I
think it's a better criteria to check whether to matched value is
quoted. If it is, it's a version number, otherwise it's a property.

So I implemented that.
@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/gradle-incorrect-pr branch from 071bbba to 40114f0 Compare March 22, 2023 17:18
@deivid-rodriguez deivid-rodriguez merged commit 33e4490 into main Mar 22, 2023
@deivid-rodriguez deivid-rodriguez deleted the deivid-rodriguez/gradle-incorrect-pr branch March 22, 2023 17:27
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.

Dependabot producing ususable PRs for Gradle version catalogues and plugins
2 participants