Giter VIP home page Giter VIP logo

rewrite-recipe-starter's Introduction

Rewrite recipe starter

This repository serves as a template for building your own recipe JARs and publishing them to a repository where they can be applied on app.moderne.io against all the public OSS code that is included there.

We've provided a sample recipe (NoGuavaListsNewArray) and a sample test class. Both of these exist as placeholders, and they should be replaced by whatever recipe you are interested in writing.

To begin, fork this repository and customize it by:

  1. Changing the root project name in settings.gradle.kts.
  2. Changing the group in build.gradle.kts.
  3. Changing the package structure from com.yourorg to whatever you want.

Getting started

Familiarize yourself with the OpenRewrite documentation, in particular the concepts & explanations op topics like the lossless semantic trees, recipes and visitors.

You might be interested to watch some of the videos available on OpenRewrite and Moderne.

Once you want to dive into the code there is a comprehensive getting started guide available in the OpenRewrite docs that provides more details than the below README.

Reference recipes

Local Publishing for Testing

Before you publish your recipe module to an artifact repository, you may want to try it out locally. To do this on the command line, run:

./gradlew publishToMavenLocal
# or ./gradlew pTML
# or mvn install

This will publish to your local maven repository, typically under ~/.m2/repository.

Replace the groupId, artifactId, recipe name, and version in the below snippets with the ones that correspond to your recipe.

In the pom.xml of a different project you wish to test your recipe out in, make your recipe module a plugin dependency of rewrite-maven-plugin:

<project>
    <build>
        <plugins>
            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>RELEASE</version>
                <configuration>
                    <activeRecipes>
                        <recipe>com.yourorg.NoGuavaListsNewArrayList</recipe>
                    </activeRecipes>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.yourorg</groupId>
                        <artifactId>rewrite-recipe-starter</artifactId>
                        <version>0.1.0-SNAPSHOT</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

Unlike Maven, Gradle must be explicitly configured to resolve dependencies from Maven local. The root project of your Gradle build, make your recipe module a dependency of the rewrite configuration:

plugins {
    id("java")
    id("org.openrewrite.rewrite") version("latest.release")
}

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    rewrite("com.yourorg:rewrite-recipe-starter:latest.integration")
}

rewrite {
    activeRecipe("com.yourorg.NoGuavaListsNewArrayList")
}

Now you can run mvn rewrite:run or gradlew rewriteRun to run your recipe.

Publishing to Artifact Repositories

This project is configured to publish to Moderne's open artifact repository (via the publishing task at the bottom of the build.gradle.kts file). If you want to publish elsewhere, you'll want to update that task. app.moderne.io can draw recipes from the provided repository, as well as from Maven Central.

Note: Running the publish task will not update app.moderne.io, as only Moderne employees can add new recipes. If you want to add your recipe to app.moderne.io, please ask the team in Slack or in Discord.

These other docs might also be useful for you depending on where you want to publish the recipe:

From Github Actions

The .github directory contains a Github action that will push a snapshot on every successful build.

Run the release action to publish a release version of a recipe.

From the command line

To build a snapshot, run ./gradlew snapshot publish to build a snapshot and publish it to Moderne's open artifact repository for inclusion at app.moderne.io.

To build a release, run ./gradlew final publish to tag a release and publish it to Moderne's open artifact repository for inclusion at app.moderne.io.

Applying OpenRewrite recipe development best practices

We maintain a collection of best practices for writing OpenRewrite recipes. You can apply these recommendations to your recipes by running the following command:

./gradlew rewriteRun -Drewrite.activeRecipe=org.openrewrite.recipes.OpenRewriteBestPractices

or

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-recommendations:RELEASE -Drewrite.activeRecipes=org.openrewrite.recipes.OpenRewriteBestPractices

rewrite-recipe-starter's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar jkschneider avatar kmccarp avatar kunli2 avatar mike-solomon avatar natedanner avatar ricmrodrigues avatar sambsnyd avatar simonverhoeven avatar sullis avatar timtebeek avatar tkvangorder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rewrite-recipe-starter's Issues

[Bug] Workflow receive-pr fails - `Task 'licenseFormat' not found`

I have forked this repository and created a PR on my fork, but the job upload-patch in the workflow receive-pr
https://github.com/timo-a/rewrite-recipe-starter/actions/runs/9051981890/job/24869151089?pr=1
fails:

Task 'licenseFormat' not found in root project 'rewrite-recipe-starter'.

I could not spot any such task in https://github.com/openrewrite/rewrite-migrate-java/blob/main/build.gradle.kts but that repo has a LICENSE file whereas this repo doesn't. Maybe that's the issue? Just tried it on my fork, adding such a file alone is not the solution.

I inadvertently created the same PR against this repo as well: #53.
If the workflow is approved there I expect the same error. Maybe that helps in the investigation, otherwise the PR can be closed.

replaceWithNewArrayListIterable fails with: NewClass type is missing or malformed

if I change:
JavaTemplate.builder(this::getCursor, "new ArrayList<>(#{any(java.lang.Iterable)})")
into
JavaTemplate.builder(this::getCursor, "new ArrayList<>(#{any(java.util.Collection)})")

it works.

question is why doesn't java.lang.Iterable work? can't detect a constructorType when the ArrayList has a contructor arg that is an Iterable - with an Integer it can

After cloning and trying to run tests on VSCode or IntelliJ I get: Unable to find runtime dependencies beginning with: 'guava'

image

java.lang.IllegalArgumentException: Unable to find runtime dependencies beginning with: 'guava'
 at org.openrewrite.java.JavaParser.dependenciesFromClasspath(JavaParser.java:104)
 at org.openrewrite.java.JavaParser$Builder.classpath(JavaParser.java:346)
 at com.yourorg.NoGuavaListsNewArrayListTest.defaults(NoGuavaListsNewArrayListTest.java:20)
 at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:136)
 at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:128)
 at com.yourorg.NoGuavaListsNewArrayListTest.replaceWithNewArrayList(NoGuavaListsNewArrayListTest.java:25)
 at java.base/java.util.ArrayList.forEach(Unknown Source)
 at java.base/java.util.ArrayList.forEach(Unknown Source)

documentation update, gradle publishToMavenLocal not working

readme.md can have commands that are needed to be used to publish on local maven repo instead of public moderne repo..

i.e. wish to know how to build, manage and reuse recipes within an enterprise, be told as this is part of custom recipe development.

gradle build results in this error

\recipe-starter>gradle build

> Configure project :
Git repository not found at F:\nag\DWork\osource\experiments\java\nfrs\openrewrite\recipe-starter -- nebula-release tasks will not be available. Use the git.root Gradle property to specify a different directory.

> Task :licenseMain FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':licenseMain' (type 'LicenseCheck').
  - In plugin 'com.hierynomus.gradle.license.LicenseBasePlugin' type 'com.hierynomus.gradle.license.tasks.LicenseCheck' property 'header' specifies file 'F:\nag\DWork\osource\experiments\java\nfrs\openrewrite\recipe-starter\gradle\licenseHeader.txt' which doesn't exist.
    
    Reason: An input file was expected to be present but it doesn't exist.
    
    Possible solutions:
      1. Make sure the file exists before the task is called.
      2. Make sure that the task which produces the file is declared as an input.
    
    For more information, please refer to https://docs.gradle.org/8.4/userguide/validation_problems.html#input_file_does_not_exist in the Gradle documentation.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.4/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 20s
9 actionable tasks: 1 executed, 8 up-to-date


`:publishToMavenLocal` no longer skips `:signNebulaPublication`

It seems like the last commit (15bdd28) broke existing functionality and :publishToMavenLocal no longer skipps :signNebulaPublication
Use case is I want to publish locally and have not set up any remote artifact repositories.

To reproduce, open the Readme in IntelliJ, click the green 'play' symbol, then 'execute line' for ./gradlew publishToMavenLocal

c17f53f (commit before the last, everything works as expected)

22:14:12: Executing 'publishToMavenLocal'...


> Configure project :
Inferred project: rewrite-recipe-starter, version: 0.1.0-SNAPSHOT

> Task :compileJava
> Task :rewriteRecipeAuthorAttributionJava
> Task :rewriteRecipeAuthorAttributionResources UP-TO-DATE
> Task :copyAttribution
> Task :processResources UP-TO-DATE
> Task :classes
> Task :createPropertiesFileForJar UP-TO-DATE
> Task :writeManifestProperties
> Task :jar
> Task :javadoc
> Task :javadocJar UP-TO-DATE
> Task :sourcesJar
> Task :generateMetadataFileForNebulaPublication SKIPPED
> Task :generatePomFileForNebulaPublication
> Task :signNebulaPublication SKIPPED
> Task :publishNebulaPublicationToMavenLocal
> Task :publishToMavenLocal

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.7/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 12s
13 actionable tasks: 9 executed, 4 up-to-date
22:14:24: Execution finished 'publishToMavenLocal'.

15bdd28 (last commit, does run :signNebulaPublication)

Execution failed for task ':signNebulaPublication'.
> Cannot perform signing task ':signNebulaPublication' because it has no configured signatory

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.7/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 23s
11 actionable tasks: 6 executed, 5 up-to-date

gradle rewriteRun

rewrite-recipe-starter>gradle rewriteRun

> Configure project :
Inferred project: rewrite-recipe-starter, version: 0.1.0-SNAPSHOT

FAILURE: Build failed with an exception.

* What went wrong:
Task 'rewriteRun' not found in root project 'rewrite-recipe-starter'.

* Try:
> Run gradle tasks to get a list of available tasks.
> For more on name expansion, please refer to https://docs.gradle.org/8.3/userguide/command_line_interface.html#sec:name_abbreviation in the Gradle documentation.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.