-
Notifications
You must be signed in to change notification settings - Fork 466
Adapted ChangeDependency to keep existing version variables when null version as input #5863
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
base: main
Are you sure you want to change the base?
Conversation
… version as input
@Jenson3210 , I'm assuming that the intent here is that the end user would then follow up with an In the current example, it would result in a failing build because no GAV for Otherwise, I think the change suggested here looks good. |
@shanman190 The idea would be that if they would want to set a new version, the code still behaves as you mention. However, not necessarily they would have to change the version. It depends on the input. But if null is the new version, the version should not be trimmed off leaving an ending We could either go for:
I decided to go for the latter. Not only because that's what we would need atm (though that plays a role 😄). When a MapNotation is used, the recipe also does not trim the version entry if null is specified. So if anything, I think this brings consistency to the recipes not depending on what syntax was used. And indeed, if we would like to set a new version, we could follow up with an |
} | ||
} | ||
if (original != updated) { | ||
String replacement = updated.toStringNotation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this solution overfit to the problem? What if the artifactId is a variable? Are we having to introduce the below logic because toStringNotation strips the variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we having to introduce the below logic because toStringNotation strips the variable?
We have to introduce something like this because DependencyStringNotationConverter.parse((String) requireNonNull(literal.getValue()))
only receives the literal part from the G.String
.
In theory, this could be group only if artifact is a variable also, in which the recipe would even give a NPE earlier in the code (as artifactId is not nullable for dependency/Gav). But as far as I remember, we mostly do not have support for setups like that as also in other recipes the assumption is always made: if it is a GString, the variable part is the version
This is also the case in our GradleDependency Trait, which uses the same DependencyStringConverter
Is this solution overfit to the problem?
Not sure what you mean with overfit, but I made it like this so that our G.String
remains a G.String
if the version is a variable so that later recipes that touch dependencies/versions receive the correct lst element instead of a literal that contains a variable reference. Other recipes that would do an update/replace by variable lookup would expect a G.String and would think a J.Literal contains the exact version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to chime in on the "overfit" part is that there is existing precedent in many of the other Gradle recipes to this respect. I agree that only expecting for only the version to be a template variable is a little assumptive, but it is the most prevalent form and very rarely do I see either the group or artifact being parameterized in real life builds.
To take this a step further, even using parameters in the way described no longer aligns with Gradle best practices and the advice there is to utilize a version catalog instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkschneider I noticed this one was moved to need additional context.
What additional context would be needed here? Or was @shanman190 and my input sufficient to take this further?
What's changed?
If the ChangeDependency has to work on a GString or a KStringTemplate, the version is most likely a variable. The code was returning a J.Literal always in this case. When the version input is null however, this would indicate the user wants to keep the current version there.
This resulted in wrong dependency declarations:
group:artifact:
By returning a new StringTemplate iso a JLiteral in the cases where newVersion is null, we can keep the
group:artifact:${variable}
AND the parameters LST object remains a StringTemplate for future recipes.What's your motivation?
Fix a hole in our input/behavior coverage.
Anyone you would like to review specifically?
@shanman190 @timtebeek @sambsnyd
Have you considered any alternatives or workarounds?
putting the variable in the
Literal
-> future recipes might not correctly recognize the variable as a variable as aJ.Literal
is found iso aG.String/K.StringTemplate
.Checklist