Add managed Maven dependency
Recipe ID
org.openrewrite.maven.AddManagedDependencyArtifactorg.openrewrite:rewrite-mavenAdd a managed Maven dependency to a pom.xml file.
Single recipeApache 2.0
Add to your build
Get a download tokenSign in with GitHub or Google, and your token replaces YOUR_DOWNLOAD_TOKEN below. Free for open source recipes like this one.
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.maven.AddManagedDependency")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite:rewrite-maven:8.92.8")
}
Then run
./gradlew rewriteRunThis recipe has required options, which a build sets in a rewrite.yml recipe that you activate instead.
Usage
You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.maven.AddManagedDependency --recipe-option "groupId=org.apache.logging.log4j" --recipe-option "artifactId=log4j-bom" --recipe-option "version=latest.release"If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite:rewrite-maven:RELEASEOptions
| Name | Type | Description |
|---|---|---|
groupIdrequired | String | The first part of a dependency coordinate 'org.apache.logging.log4j:ARTIFACT_ID:VERSION'. e.g. org.apache.logging.log4j |
artifactIdrequired | String | The second part of a dependency coordinate 'org.apache.logging.log4j:log4j-bom:VERSION'. e.g. log4j-bom |
versionrequired | String | An exact version number or node-style semver selector used to select the version number. e.g. latest.release |
scope | String | An optional scope to use for the dependency management tag. e.g. import |
type | String | An optional type to use for the dependency management tag. e.g. pom |
classifier | String | An optional classifier to use for the dependency management tag e.g. test |
versionPattern | String | Allows version selection to be extended beyond the original Node Semver semantics. So for example,Setting 'version' to "25-29" can be paired with a metadata pattern of "-jre" to select 29.0-jre e.g. -jre |
releasesOnly | Boolean | Whether to exclude snapshots from consideration when using a semver selector |
onlyIfUsing | String | Only add managed dependencies to projects having a dependency matching the expression. e.g. org.apache.logging.log4j:log4j* |
addToRootPom | Boolean | Add to the root pom where root is the eldest parent of the pom within the source set. |
because | String | The reason for adding the managed dependency. This will be added as an XML comment preceding the managed dependency. e.g. CVE-2021-1234 |
Data tables
Structured output this recipe can produce.
- Maven metadata failuresAttempts to resolve maven metadata that failed.
org.openrewrite.maven.table.MavenMetadataFailures - Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats