Add a new property
Recipe ID
org.openrewrite.properties.AddPropertyArtifactorg.openrewrite:rewrite-propertiesAdds a new property to a property file. Attempts to place the new property in alphabetical order by the property keys. Whitespace before and after the = must be included in the property and value.
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.properties.AddProperty")
}
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-properties: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.properties.AddProperty --recipe-option "property=management.metrics.enable.process.files" --recipe-option "value=newPropValue"If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite:rewrite-properties:RELEASEOptions
| Name | Type | Description |
|---|---|---|
propertyrequired | String | The property key to add. e.g. management.metrics.enable.process.files |
valuerequired | String | The value of the new property key. e.g. newPropValue |
comment | String | A comment that will be added to the new property. e.g. This is a comment |
delimiter | String | Property entries support different delimiters (=, :, or whitespace). The default value is = unless provided the delimiter of the new property entry.e.g. : |
orderedInsertion | Boolean | Whether to attempt adding the property in an order following alphabetic sorting. The default value is true.e.g. false |
insertMode | InsertMode | Choose an insertion point relative to an existing property. Default is Last. Takes precedence over orderedInsertion. If the referenced property does not exist, falls back to default behavior. |
insertProperty | String | The key of an existing property to use as the reference point for the insert mode. Required when insertMode is Before or After.e.g. server.port |
Data tables
Structured output this recipe can produce.
- 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