Closed iuliiasobolevska closed 12 months ago
Thanks for reporting this issue here and pinpointing the exact point at which you first see this issue occur. Just to be clear: do you still see this issue with the most recent 6.3.8 release of rewrite-gradle-plugin ?
Thanks for the helpful sample project too! When I run ./gradlew rewriteRun
on that I indeed see a new application.yml
file added to the root, in addition to changes to the intended src/main/resources/application.yml
. 😞
Hi Tim!
Just to be clear: do you still see this issue with the most recent 6.3.8 release of rewrite-gradle-plugin ?
Yes, I still get it with rewrite-gradle-plugin:6.3.8
.
When I run ./gradlew rewriteRun on that I indeed see a new application.yml file added to the root, in addition to changes to the intended src/main/resources/application.yml.
For single-module projects (e.g. my example repo) it at least updates the intended src/main/resources/application.yml
so the only impact is an extra file. For multi-module projects, it just creates 2 extra files and the intended ones are not being updated. Given that most of our projects are multi-module ones, this bug is pretty severe (we are not blocked as we pinned to 6.1.26 for now but I can't verify other issues since we are not on the latest).
Hmm yes pinning is not ideal; I've been trying for bit to replicate the issue, first starting with the OmniParser that was added in the switch to 6.2.0; no such luck there yet with a test added to OmniParserTest
@Test
@Issue("https://github.com/openrewrite/rewrite-gradle-plugin/issues/231")
void applicationResourcesParsedOnce() throws Exception {
OmniParser parser = OmniParser.builder(OmniParser.RESOURCE_PARSERS)
.build();
List<SourceFile> sourceFileStream = parser.parseAll(Path.of("src/test/resources/demo")).toList();
assertThat(sourceFileStream).hasSize(2); // pom.xml and application.yml
ChangePropertyKey changePropertyKey = new ChangePropertyKey("foo.bar", "bar.foo", null, null);
Yaml.Documents visited = (Yaml.Documents) changePropertyKey.getVisitor().visit(sourceFileStream.get(1), null);
assertThat(((Yaml.Mapping)visited.getDocuments().get(0).getBlock()).getEntries().get(0).getKey().getValue()).isEqualTo("bar.foo");
}
Next stop is likely a test in this project, but likely after the weekend for me, if I get to it then with talks to prepare & give.
Unless @sambsnyd is able to have a look; I know he's looked into duplicate files in the past week as well.
I am taking a look at this
Thanks for reporting @iuliiasobolevska ! I will be issuing a new plugin release to get this fix out there soon
Thank you both for the quick turnaround! Highly appreciated!
When
org.openrewrite:plugin
gets upgraded from6.1.26
to6.2.0
(diff between versions), all recipes based onorg.openrewrite.properties.ChangePropertyKey
create newapplication.yml/application.properties
files in the root of the project and undersrc/main/resources
folder:instead of updating the
application.yml/application.properties
files already present in the project.The issue is reproducible both for single and multi-module projects by adding a property to be updated and running any
ChangePropertyKey
-based recipe, e.g. addto
application.yml
file and runorg.openrewrite.java.spring.boot3.SpringBootProperties_3_0
recipe. See openrewritedemo.zip.