Comments (7)
Hey @dpozinen, #3992 should have fixed that, but the following still does not work out of the box:
type: specs.openrewrite.org/v1beta/recipe
name: org.ammachado.MyCustomRecipe
displayName: My custom recipe
description: Fix all the things.
recipeList:
- org.openrewrite.maven.ChangePropertyValue:
key: quarkus.platform.group-id
newValue: io.quarkus.platform
addIfMissing: "True"
- org.openrewrite.maven.ChangePropertyValue:
key: quarkus.platform.artifact-id
newValue: quarkus-bom
addIfMissing: "True"
- org.openrewrite.maven.ChangePropertyValue:
key: quarkus.platform.version
newValue: 3.2.3.Final
addIfMissing: "True"
- org.openrewrite.maven.AddManagedDependency:
groupId: ${quarkus.platform.group-id}
artifactId: ${quarkus.platform.artifact-id}
version: ${quarkus.platform.version}
scope: import
type: pom
addToRootPom: "True"
The properties will be added, but the dependency will fail to resolve, because the placeholders were not resolved.
I think that ChangePropertyValue
is just missing a call to maybeUpdateModel()
on visitDocument
. I wrote a recipe to force the maven model to be updated. I use it before my org.openrewrite.maven.AddManagedDependency
recipes, and it works as expected.
Updated example
type: specs.openrewrite.org/v1beta/recipe
name: org.ammachado.MyCustomRecipe
displayName: My custom recipe
description: Fix all the things.
recipeList:
- org.openrewrite.maven.ChangePropertyValue:
key: quarkus.platform.group-id
newValue: io.quarkus.platform
addIfMissing: "True"
- org.openrewrite.maven.ChangePropertyValue:
key: quarkus.platform.artifact-id
newValue: quarkus-bom
addIfMissing: "True"
- org.openrewrite.maven.ChangePropertyValue:
key: quarkus.platform.version
newValue: 3.2.3.Final
addIfMissing: "True"
- org.ammachado.ForceMavenModelUpdate
- org.openrewrite.maven.AddManagedDependency:
groupId: ${quarkus.platform.group-id}
artifactId: ${quarkus.platform.artifact-id}
version: ${quarkus.platform.version}
scope: import
type: pom
addToRootPom: "True"
org.ammachado.ForceMavenModelUpdate
recipe source
public class ForceMavenModelUpdate extends Recipe {
@Override
public String getDisplayName() {
return "Force Maven Model Update";
}
@Override
public String getDescription() {
return "This recipe will force the Maven model to be updated.";
}
@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new UpdateMavenModel<>();
}
}
@timtebeek, the Yaml from the example was just created using https://app.moderne.io. Booleans are showing "True"
, instead of true
. Is that a problem as well?
from rewrite.
Thanks for the suggestion @dpozinen ; how would you envision this to work both in terms of configuration, and in terms of when the recipe runs? Because I have quite a few questions when I think through how to implement this, and I'll list a few below.
Right now the recipe already has quite an array of options: https://docs.openrewrite.org/recipes/maven/addmanageddependency
- Were we to allow
version: ${something.version}
then we'd need to also know the actual version. How would you pass that in? - Should the property already exist, or should it be created?
- How to handle conflicts if we create the property?
- Should we honor any parent properties or override?
I'm thinking if we add option to indicate that the version should be placed in a property, then the naming of that property is going to be very much specific to one's particular taste. Some projects prefer <version.abc>
whereas others prefer <abc.version>
, and for instance any Spring migration recipes should ideally not force one over the other.
We're constantly trying to balance feature requests with usability and maintainability by thinking through some of these above edge cases. Since versions can be updated through recipes, we tend to favor just having them where they are used rather than add indirection.
If you do want to keep managed dependency versions in properties consistently then perhaps a dedicated recipe could make sense. That also has the benefit of not further complicating the logic for AddManagedDependency, so it's something to consider.
from rewrite.
oh nice, #3992 indeed added this possibility, things move fast lol; apologies for not checking first.
And indeed what you're describing @ammachado is what we're trying to do (add property and then use it), will try your workaround for maven model update, thanks!
from rewrite.
Thanks for chiming in @ammachado ! Indeed that org.ammachado.ForceMavenModelUpdate
utility would solve this right after adding the properties. I'm wondering if we should call that maybeUpdateModel()
from ChangePropertyValue
, and what any performance impact of that would be. Could be nice to have things "just work" rather than require such a workaround. 🤔
As for the "True"
in the recipe builder output, I think that should be fine based on how that field is a nullable java.lang.Boolean
, not a boolean
. We load those values in here, and I've not heard any issues about their values so far 🤞🏻
from rewrite.
Related Issues (20)
- UpdateMavenWrapper inconsistent when the wrapper is in a nested directory HOT 10
- Trailing comma in an array end up in white-space HOT 2
- Declarative Preconditions - `or` association
- Declarative Preconditions - Control applicability to ScanningRecipes HOT 6
- Split method signature line into multiple lines based on the length HOT 1
- Add or merge content to yaml file HOT 7
- Create YAML File with remote content HOT 2
- Create a folder HOT 9
- [Windows build from source] Gradle JDK auto-download doesn't work as expected HOT 2
- Unirest 4.x HOT 1
- foo.properties is not print idempotent due to `key==value` HOT 1
- `ChangeType` not working with types provided to the parser using `dependsOn`. HOT 6
- RemoveObjectsIsNull doesn't remove unnecessary parentheses, if it HOT 1
- org.openrewrite.gradle.RemoveDependency does not remove dependency in subproject HOT 3
- Performance issue with classpath scanning HOT 2
- Openrewrite: apply recipe list step by step (to have a proper commit history) HOT 1
- `module-info.java` trips up the JavaParser and Gradle/Maven plugin HOT 35
- Problem with parsing groovy files HOT 1
- RenameVariable does not modify variables referenced through type casts HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rewrite.