Skip to content
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

Running the UpdateGradleWrapper recipe for a Gradle project without wrapper should generate a functioning wrapper JAR #4878

Open
bmuschko opened this issue Jan 9, 2025 · 11 comments
Labels
bug Something isn't working

Comments

@bmuschko
Copy link
Contributor

bmuschko commented Jan 9, 2025

What version of OpenRewrite are you using?

  • Moderne CLI 3.26.2
  • OpenRewrite v8.42.5

How are you running OpenRewrite?

Moderne CLI

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

Clone a Gradle project that does not include a checked-in wrapper.

$ mod config recipes jar install org.openrewrite:rewrite-gradle:LATEST
$ git clone https://github.com/bmuschko/mod-gradle-wrapper.git
$ mod build .
$ mod run . --recipe=org.openrewrite.gradle.UpdateGradleWrapper
$ mod git apply . --last-recipe-run
$ cd gradle/wrapper
$ ls -l
-rw-r--r--@ 1 bmuschko  staff    0 Jan  9 14:21 gradle-wrapper.jar
-rw-r--r--@ 1 bmuschko  staff  287 Jan  9 14:21 gradle-wrapper.properties

What did you expect to see?

A functioning Gradle wrapper.

What did you see instead?

The generated wrapper JAR file has a size of zero bytes. Executing the build with the wrapper fails.

./gradlew tasks
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain

Are you interested in [contributing a fix to OpenRewrite]

Not for this one

@bmuschko bmuschko added the bug Something isn't working label Jan 9, 2025
@shanman190
Copy link
Contributor

This is peculiar.

@bmuschko, just to make sure, in your current location you are able to hit services.gradle.org, correct?

In the test bed, we have a test that handles this case including confirming that the wrapper jar itself is valid.
https://github.com/openrewrite/rewrite/blob/main/rewrite-gradle%2Fsrc%2Ftest%2Fjava%2Forg%2Fopenrewrite%2Fgradle%2FUpdateGradleWrapperTest.java#L102

@bmuschko
Copy link
Contributor Author

bmuschko commented Jan 9, 2025

Yes, I can reach services.gradle.org.

$ ping services.gradle.org
PING services.gradle.org (104.16.73.101): 56 data bytes
64 bytes from 104.16.73.101: icmp_seq=0 ttl=55 time=14.855 ms

@bmuschko
Copy link
Contributor Author

@shanman190 Were you able to find out about the root cause?

@shanman190
Copy link
Contributor

@bmuschko, I haven't yet. I'm hoping to look into that this afternoon.

@shanman190
Copy link
Contributor

Ok, after doing some testing I've found the following:

  • RewriteTest: ✅
  • OSS Gradle plugin: ✅
  • Moderne CLI: ❌

I'm pretty sure I know why the Moderne CLI is failing.

@bmuschko
Copy link
Contributor Author

Great, thanks for looking into this. Apart from the Moderne CLI, I am seeing the same issue on the Sass where I call this recipe from another one. The root cause may be the same.

@shanman190
Copy link
Contributor

shanman190 commented Jan 15, 2025

@bmuschko, on the SaaS I was able to successfully add the Gradle wrapper to a Gradle project that lacked the wrapper initially.

https://app.moderne.io/commits/de828a2b-04e6-4768-a79c-6c7587a8890b

So for me, only the Moderne CLI is failing to work correctly.

@bmuschko
Copy link
Contributor Author

@shanman190 I might be wrong here. That's what I thought had happened. I will try that again on my end.

@bmuschko
Copy link
Contributor Author

@shanman190 I wrote a test case that implements RewriteTest and it looks like the size of the wrapper JAR is larger than zero bytes. So I'd assume that the the issue is specific to the Moderne CLI as of now.

@timtebeek
Copy link
Contributor

Thanks both! I'll log a separate issue for the CLI, but I wonder if we have the same problem when using dryRun in the Maven and Gradle plugins, as that similarly creates a .patch file that would then have to include the binary added here. 🤔

@shanman190
Copy link
Contributor

@timtebeek, the answer there is yes. If you do a dryRun, then try to apply the Git patch any Remote elements will end up with empty files because the patch doesn't contain their content.

@timtebeek timtebeek moved this to Backlog in OpenRewrite Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

3 participants