-
Notifications
You must be signed in to change notification settings - Fork 376
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
GroovyParsingException when parsing Gradle build file #5072
Comments
Any improvement with the latest releases? There were fixes specifically for the Groovy parser: |
Thanks for the suggestion, but just tried 8.46.1 and unfortunately still seeing the same error (8.47.0 doesn't seem available in maven central yet). |
I've just tried reproducing by creating these two files in an empty directory and running Also adding the two lines:
in a unit test for So I think there might be a bit more of a nuance to pinpoint the actual issue here. |
Hi @greg-at-moderne, thanks for trying, did you use Gradle 6.9 also? |
Ah. No. I didn't. I've used 8.12. Maybe that's the thing. |
When I try
|
Hi @greg-at-moderne, In your logs I see "there were problems parsing build.gradle", I think if you run your build with --info it will show the stack trace I seen |
And you are right indeed!
But it looks too similar to yours for it to be an accident. Thanks! |
Just some extra info - I just tried with Java 11, and then the stack trace looks like yours, I was previously using Java 8. |
So it's probably the parentheses. Gradle 6.x I believe uses Groovy 2.5 while Gradle 7.x uses Groovy 3.x. One of the features that comes with Groovy 3.x is better recording of parentheses depth which rewrite-groovy takes advantage of when it's available, but has to fallback to trying to guess the parentheses depth on these older versions. |
When I was previously debugging this, I did notice that when using Gradle 8, the parentheses level of the * node was 0, whereas in Gradle 6 it was 1. I think the |
I can confirm it's probably the parentheses stuff. I I disable both the retrieval of the flag and the fallback: private @Nullable Integer getInsideParenthesesLevel(ASTNode node) {
Object rawIpl = null; //node.getNodeMetaData("_INSIDE_PARENTHESES_LEVEL");
..
} else if (node instanceof BinaryExpression) {
BinaryExpression expr = (BinaryExpression) node;
// return determineParenthesisLevel(expr.getLeftExpression().getLineNumber(), expr.getLineNumber(), expr.getLeftExpression().getColumnNumber(), expr.getColumnNumber());
}
return null;
} And I use following unit test: @Test
void doTest() {
rewriteRun(
groovy(
"""
def x = (1 / 1 ) * 100
"""
)
);
} I'll get the error:
N.B. There is still a debate going on if (and how) we are going to create Groovy 2 unit tests. |
So one way for Groovy 2.x tests could be to utilize the jvm-teat-suite plugin to have unique test suites. Depends a little on how much test duplication want to avoid. |
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the Gradle plugin, with an init script.
What is the smallest, simplest way to reproduce the problem?
I have simplified my original
build.gradle
to something which produces a similar exception. I have been unable to reproduce this in a unit test since they use Groovy 3, which doesn't seem to produce the exception. I have tried to create a unit test with Groovy 2 dependencies, but it seemed the GroovyParserVisitor then sees a ClassNotFoundException for LamdaExpression, so I'm unsure how to configure a test to compile the Groovy code with Groovy 2 yet have Groovy 3 classes available. The only way I have been able to reproduce is by actually runninggradle --init-script init.gradle rewriteDryRun
.init.gradle
build.gradle
What did you expect to see?
No fail to parse errors.
What did you see instead?
Failed to parse error.
What is the full stack trace of any errors you encountered?
Are you interested in contributing a fix to OpenRewrite?
The text was updated successfully, but these errors were encountered: