openrewrite / openrewrite/rewrite

GroovyParser should not report a warning when setting a writable property

Open
#4,908 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug gradle
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

What version of OpenRewrite are you using?

  • OpenRewrite v8.43.1

How are you running OpenRewrite?

As a test that implements RecipeTest executed by Gradle. I also added a logging library to my test execution classpath.

testRuntimeOnly("org.slf4j:slf4j-simple:2.0.16")

What is the smallest, simplest way to reproduce the problem?

Write a custom recipe that generate a Gradle build file, along the lines of the following:

private SourceFile generateBuildFile(ExecutionContext ctx) {
     String buildFileContent = """
          plugins {
              id 'java'
          }
                
          version = '1.2.3'
    """;

    return GradleParser.builder().build()
               .parseInputs(singletonList(Parser.Input.fromString(Paths.get("build.gradle"), buildFileContent)), null, ctx)
               .findFirst().get();
}

What did you expect to see?

No warning from the Groovy parser. The property Project.version has a setter method.

What did you see instead?

The following output when executing the test with Gradle.

[Test worker] WARN org.openrewrite.groovy.GroovyParser - doesntmatter: 5: [Static type checking] - Cannot set read-only property: version
 @ line 5, column 1.
   version = '1.2.3'
   ^

1 error

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the warning with the custom RecipeTest and GradleParser input shown in the issue, then start by tracing GroovyParser handling of the version = '1.2.3' assignment. Confirm the fix by running the test with the generated Gradle build file and verifying that no read-only-property warning is emitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.