Creating Open Rewrite Recipeies in Existing Project.

I have been hard at work porting my entire Server Code over to Kotlin from Java, Mainly to reduce possibility of nullpointers and extension functions. Intelijs change over is a bit scuffed so I had a look arouznd in the Intelij whether there are things that might be able to undo that behaviour realtively easily. During that experimentation I stumbled across Open Rewrite Template: https://github.com/moderneinc/rewrite-recipe-starter However I want to integrate it into an existing Project as Gradle Sub Project to avoid having to publish to local repo nen Stuff all the time. Having to swap between Intelij Projects is also annoying. I tried to get just a custom self made recipe to run to then code my own but so far to no avail. And I for tried HOURS. (I know tht doing it manually would be faster. But I hope to learn from it and use it in the future. If I get it to run at least.)
Recipe development environment | OpenRewrite Docs
Instructions for setting up your local development environment to create OpenRewrite recipes.
GitHub
GitHub - moderneinc/rewrite-recipe-starter: A forkable starter for ...
A forkable starter for building your own recipes and deploying them on the Moderne SaaS - moderneinc/rewrite-recipe-starter
No description
No description
No description
No description
No description
No description
31 Replies
JavaBot
JavaBot7mo ago
This post has been reserved for your question.
Hey @Hype_the_Time (PING ON REPLY)! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JavaBot
JavaBot7mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
dan1st
dan1st7mo ago
What is the exact issue that happens with your custom recipe?
Hype_the_Time (PING ON REPLY)
im just trying to even get 1 to "run" like i basically dont get grade configured or rather open rewrite using gradle
dan1st
dan1st7mo ago
and what happens when trying to run it? Is it ignored? Are you getting an exception? Does the build fail?
Hype_the_Time (PING ON REPLY)
if i run main build. it runs just fine (BUILD SUCCESSFUL in 32s) Rewruite run was causing issues. I noticed 2 things which i thought i did previously which did not cause an errors as i saw them earlier. Im checking stuff rn
dan1st
dan1st7mo ago
What exactly are you running that is causing issues and what exactly happens?
Hype_the_Time (PING ON REPLY)
it was unable to find the recipe previously. this time it for some reason worked. im checking stuff on my own and will come back to this once I get into an issue again. idk why it works now. Rewrite configuration file /home/spieler/IdeaProjects/BingoNet-Server/main/resources/META-INF/rewrite/BN-Server.yml does not exist. Validating active recipes Scanning sources in project :main Using active styles [] first time i saw Rewrite configuration file /home/spieler/IdeaProjects/BingoNet-Server/main/resources/META-INF/rewrite/BN-Server.yml does not exist. wait nvm does not exiost instead of does exist
dan1st
dan1st7mo ago
Well, does the file exist? yes
dan1st
dan1st7mo ago
and the main is in /home/spieler/IdeaProjects/BingoNet-Server?
dan1st
dan1st7mo ago
Can you run ls -la /home/spieler/IdeaProjects/BingoNet-Server/main/resources/META-INF/rewrite/BN-Server.yml in a terminal and show the output?
Hype_the_Time (PING ON REPLY)
copying that file path via intlij: /home/spieler/IdeaProjects/BingoNet-Server/main/src/main/resources/META-INF/rewrite/BN-Server.yml
dan1st
dan1st7mo ago
main/src/main/resources
Hype_the_Time (PING ON REPLY)
wait diff
dan1st
dan1st7mo ago
yep
Hype_the_Time (PING ON REPLY)
questuion is where its taking that from ah found sth BUILD SUCCESSFUL in 34s question is on how to get the breakpoint in the file activated
dan1st
dan1st7mo ago
?
Hype_the_Time (PING ON REPLY)
in the custom recipe
dan1st
dan1st7mo ago
What do you mean with getting the breakpoint in that file activated?
Dexter
Dexter7mo ago
in package de.hype.openrewrite.recipes; import org.openrewrite.ExecutionContext; import org.openrewrite.NlsRewrite; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.kotlin.KotlinIsoVisitor; import org.openrewrite.kotlin.tree.K;
public class ChangeGetterPropertyToFunction extends Recipe {
@Override
public @NlsRewrite.DisplayName String getDisplayName() {
return "Change getter property to function";
}

@Override
public @NlsRewrite.Description String getDescription() {
return "Change getter property to function";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new KotlinIsoVisitor<>() {
@Override
public K.Property visitProperty(K.Property property, ExecutionContext executionContext) {
// Logic to change getter property to function
return super.visitProperty(property, executionContext);
}
};
}
}
public class ChangeGetterPropertyToFunction extends Recipe {
@Override
public @NlsRewrite.DisplayName String getDisplayName() {
return "Change getter property to function";
}

@Override
public @NlsRewrite.Description String getDescription() {
return "Change getter property to function";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new KotlinIsoVisitor<>() {
@Override
public K.Property visitProperty(K.Property property, ExecutionContext executionContext) {
// Logic to change getter property to function
return super.visitProperty(property, executionContext);
}
};
}
}
This message has been formatted automatically. You can disable this using /preferences.
dan1st
dan1st7mo ago
Do you have a breakpoint in that file for debugging?
Hype_the_Time (PING ON REPLY)
just noticed that its not having gradle dameon off yet
dan1st
dan1st7mo ago
ok so Gradle doesn't run with a debugger attached but you should be able to just attach a debugger to Gradle Are you running the Gradle build from the terminal? If so, what exact command are you using?
Hype_the_Time (PING ON REPLY)
ah daemon off worked
dan1st
dan1st7mo ago
ah ok I think alternatively, you could just attach a debugger to the daemon
JavaBot
JavaBot7mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?