generated from moderneinc/rewrite-recipe-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 98d3cda
Showing
20 changed files
with
909 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
version: 2 | ||
updates: | ||
- package-ecosystem: github-actions | ||
directory: / | ||
schedule: | ||
interval: weekly | ||
commit-message: | ||
prefix: "chore(ci)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
name: ci | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags-ignore: | ||
- "*" | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
env: | ||
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"' | ||
GRADLE_SWITCHES: "-s --console=plain --info --stacktrace" | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: ["ubuntu-latest"] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: set-up-jdk | ||
uses: actions/[email protected] | ||
with: | ||
distribution: zulu | ||
java-version: 17 | ||
cache: gradle | ||
- name: build | ||
run: ./gradlew ${GRADLE_SWITCHES} build test | ||
|
||
publish-snapshots: | ||
needs: [build] | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: set-up-jdk | ||
uses: actions/[email protected] | ||
with: | ||
distribution: zulu | ||
java-version: 17 | ||
cache: gradle | ||
- name: publish-snapshots | ||
if: github.event_name == 'push' | ||
timeout-minutes: 30 | ||
run: ./gradlew ${GRADLE_SWITCHES} snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
name: "Validate Gradle Wrapper" | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
validation: | ||
name: "Validation" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: gradle/wrapper-validation-action@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
name: publish | ||
|
||
on: | ||
push: | ||
tags: | ||
- v[0-9]+.[0-9]+.[0-9]+ | ||
- v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+ | ||
|
||
env: | ||
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"' | ||
GRADLE_SWITCHES: "-s --console=plain --info --stacktrace" | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: set-up-jdk | ||
uses: actions/[email protected] | ||
with: | ||
distribution: zulu | ||
java-version: 17 | ||
cache: gradle | ||
|
||
- name: publish-candidate | ||
if: contains(github.ref, '-rc.') | ||
timeout-minutes: 30 | ||
run: ./gradlew ${GRADLE_SWITCHES} -Preleasing -Prelease.disableGitChecks=true -Prelease.useLastTag=true candidate publish | ||
|
||
- name: publish-release | ||
if: (!contains(github.ref, '-rc.')) | ||
timeout-minutes: 30 | ||
run: ./gradlew ${GRADLE_SWITCHES} -Preleasing -Prelease.disableGitChecks=true -Prelease.useLastTag=true final publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build/ | ||
.gradle/ | ||
.idea/ | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
## 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](https://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. | ||
|
||
## Detailed Guide | ||
|
||
There is a [comprehensive getting started guide](https://docs.openrewrite.org/authoring-recipes/recipe-development-environment) | ||
available in the OpenRewrite docs that provides more details than the below README. | ||
|
||
## 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: | ||
```bash | ||
./gradlew publishToMavenLocal | ||
# or ./gradlew pTML | ||
``` | ||
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: | ||
```xml | ||
<project> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.openrewrite.maven</groupId> | ||
<artifactId>rewrite-maven-plugin</artifactId> | ||
<version>5.2.4</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: | ||
|
||
```groovy | ||
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](https://app.moderne.io) can draw recipes from the provided repository, as well as from [Maven Central](https://search.maven.org). | ||
|
||
Note: | ||
Running the publish task _will not_ update [app.moderne.io](https://app.moderne.io), as only Moderne employees can | ||
add new recipes. If you want to add your recipe to [app.moderne.io](https://app.moderne.io), please ask the | ||
team in [Slack](https://join.slack.com/t/rewriteoss/shared_invite/zt-nj42n3ea-b~62rIHzb3Vo0E1APKCXEA) or in [Discord](https://discord.gg/xk3ZKrhWAb). | ||
|
||
These other docs might also be useful for you depending on where you want to publish the recipe: | ||
|
||
* Sonatype's instructions for [publishing to Maven Central](https://maven.apache.org/repository/guide-central-repository-upload.html) | ||
* Gradle's instructions on the [Gradle Publishing Plugin](https://docs.gradle.org/current/userguide/publishing\_maven.html). | ||
|
||
### 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](https://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](https://app.moderne.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
plugins { | ||
id("org.openrewrite.build.recipe-library") version "latest.release" | ||
} | ||
|
||
// Set as appropriate for your organization | ||
group = "com.yourorg" | ||
description = "Rewrite recipes." | ||
|
||
// The bom version can also be set to a specific version or latest.release. | ||
val latest = "latest.integration" | ||
dependencies { | ||
implementation(platform("org.openrewrite:rewrite-bom:${latest}")) | ||
|
||
implementation("org.openrewrite:rewrite-java") | ||
runtimeOnly("org.openrewrite:rewrite-java-17") | ||
// Need to have a slf4j binding to see any output enabled from the parser. | ||
runtimeOnly("ch.qos.logback:logback-classic:1.2.+") | ||
|
||
testRuntimeOnly("com.google.guava:guava:latest.release") | ||
} | ||
|
||
configure<PublishingExtension> { | ||
publications { | ||
named("nebula", MavenPublication::class.java) { | ||
suppressPomMetadataWarningsFor("runtimeElements") | ||
} | ||
} | ||
} | ||
|
||
publishing { | ||
repositories { | ||
maven { | ||
name = "moderne" | ||
url = uri("https://us-west1-maven.pkg.dev/moderne-dev/moderne-recipe") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright 2023 the original author or authors. | ||
<p> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
<p> | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
<p> | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.