|
| 1 | +--- |
| 2 | +sidebar_label: "Remove redundant security resolution rules" |
| 3 | +--- |
| 4 | + |
| 5 | +import Tabs from '@theme/Tabs'; |
| 6 | +import TabItem from '@theme/TabItem'; |
| 7 | + |
| 8 | +# Remove redundant security resolution rules |
| 9 | + |
| 10 | +**org.openrewrite.gradle.RemoveRedundantSecurityResolutionRules** |
| 11 | + |
| 12 | +_Remove `resolutionStrategy.eachDependency` rules that pin dependencies to versions that are already being managed by a platform/BOM to equal or newer versions. Only removes rules that have a security advisory identifier (CVE or GHSA) in the `because` clause, unless a custom pattern is specified._ |
| 13 | + |
| 14 | +### Tags |
| 15 | + |
| 16 | +* [security](/reference/recipes-by-tag#security) |
| 17 | + |
| 18 | +## Recipe source |
| 19 | + |
| 20 | +[GitHub](https://github.com/openrewrite/rewrite/blob/main/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveRedundantSecurityResolutionRules.java), |
| 21 | +[Issue Tracker](https://github.com/openrewrite/rewrite/issues), |
| 22 | +[Maven Central](https://central.sonatype.com/artifact/org.openrewrite/rewrite-gradle/) |
| 23 | + |
| 24 | +This recipe is available under the [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0). |
| 25 | + |
| 26 | +## Options |
| 27 | + |
| 28 | +| Type | Name | Description | Example | |
| 29 | +| --- | --- | --- | --- | |
| 30 | +| `String` | securityPattern | *Optional*. A regular expression pattern to identify security-related resolution rules by matching against the `because` clause. Rules matching this pattern will be considered for removal. The pattern is searched within the clause, so a `because` containing multiple identifiers (e.g., `CVE-2024-1234, GHSA-abcd-1234-efgh`) will match if any identifier matches. Default pattern matches CVE identifiers (e.g., `CVE-2024-1234`) and GitHub Security Advisory identifiers (e.g., `GHSA-xxxx-xxxx-xxxx`). | `(CVE-\d|GHSA-[a-z0-9])` | |
| 31 | + |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +This recipe has no required configuration parameters and comes from a rewrite core library. It can be activated directly without adding any dependencies. |
| 36 | +<Tabs groupId="projectType"> |
| 37 | +<TabItem value="gradle" label="Gradle"> |
| 38 | + |
| 39 | +1. Add the following to your `build.gradle` file: |
| 40 | + |
| 41 | +```groovy title="build.gradle" |
| 42 | +plugins { |
| 43 | + id("org.openrewrite.rewrite") version("latest.release") |
| 44 | +} |
| 45 | +
|
| 46 | +rewrite { |
| 47 | + activeRecipe("org.openrewrite.gradle.RemoveRedundantSecurityResolutionRules") |
| 48 | + setExportDatatables(true) |
| 49 | +} |
| 50 | +
|
| 51 | +repositories { |
| 52 | + mavenCentral() |
| 53 | +} |
| 54 | +
|
| 55 | +``` |
| 56 | +2. Run `gradle rewriteRun` to run the recipe. |
| 57 | +</TabItem> |
| 58 | + |
| 59 | +<TabItem value="gradle-init-script" label="Gradle init script"> |
| 60 | + |
| 61 | +1. Create a file named `init.gradle` in the root of your project. |
| 62 | + |
| 63 | +```groovy title="init.gradle" |
| 64 | +initscript { |
| 65 | + repositories { |
| 66 | + maven { url "https://plugins.gradle.org/m2" } |
| 67 | + } |
| 68 | + dependencies { classpath("org.openrewrite:plugin:latest.release") } |
| 69 | +} |
| 70 | +rootProject { |
| 71 | + plugins.apply(org.openrewrite.gradle.RewritePlugin) |
| 72 | + dependencies { |
| 73 | + rewrite("org.openrewrite:rewrite-java") |
| 74 | + } |
| 75 | + rewrite { |
| 76 | + activeRecipe("org.openrewrite.gradle.RemoveRedundantSecurityResolutionRules") |
| 77 | + setExportDatatables(true) |
| 78 | + } |
| 79 | + afterEvaluate { |
| 80 | + if (repositories.isEmpty()) { |
| 81 | + repositories { |
| 82 | + mavenCentral() |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +2. Run the recipe. |
| 90 | + |
| 91 | +```shell title="shell" |
| 92 | +gradle --init-script init.gradle rewriteRun |
| 93 | +``` |
| 94 | +</TabItem> |
| 95 | + |
| 96 | +<TabItem value="moderne-cli" label="Moderne CLI"> |
| 97 | + |
| 98 | +You will need to have configured the [Moderne CLI](https://docs.moderne.io/user-documentation/moderne-cli/getting-started/cli-intro) on your machine before you can run the following command. |
| 99 | + |
| 100 | +```shell title="shell" |
| 101 | +mod run . --recipe RemoveRedundantSecurityResolutionRules |
| 102 | +``` |
| 103 | + |
| 104 | +If the recipe is not available locally, then you can install it using: |
| 105 | +```shell |
| 106 | +mod config recipes jar install org.openrewrite:rewrite-gradle:{{VERSION_ORG_OPENREWRITE_REWRITE_GRADLE}} |
| 107 | +``` |
| 108 | +</TabItem> |
| 109 | +</Tabs> |
| 110 | + |
| 111 | +## See how this recipe works across multiple open-source repositories |
| 112 | + |
| 113 | +import RecipeCallout from '@site/src/components/ModerneLink'; |
| 114 | + |
| 115 | +<RecipeCallout link="https://app.moderne.io/recipes/org.openrewrite.gradle.RemoveRedundantSecurityResolutionRules" /> |
| 116 | + |
| 117 | +The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories. |
| 118 | + |
| 119 | +Please [contact Moderne](https://moderne.io/product) for more information about safely running the recipes on your own codebase in a private SaaS. |
| 120 | +## Data Tables |
| 121 | + |
| 122 | +<Tabs groupId="data-tables"> |
| 123 | +<TabItem value="org.openrewrite.table.SourcesFileResults" label="SourcesFileResults"> |
| 124 | + |
| 125 | +### Source files that had results |
| 126 | +**org.openrewrite.table.SourcesFileResults** |
| 127 | + |
| 128 | +_Source files that were modified by the recipe run._ |
| 129 | + |
| 130 | +| Column Name | Description | |
| 131 | +| ----------- | ----------- | |
| 132 | +| Source path before the run | The source path of the file before the run. `null` when a source file was created during the run. | |
| 133 | +| Source path after the run | A recipe may modify the source path. This is the path after the run. `null` when a source file was deleted during the run. | |
| 134 | +| Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. | |
| 135 | +| Recipe that made changes | The specific recipe that made a change. | |
| 136 | +| Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. | |
| 137 | +| Cycle | The recipe cycle in which the change was made. | |
| 138 | + |
| 139 | +</TabItem> |
| 140 | + |
| 141 | +<TabItem value="org.openrewrite.table.SearchResults" label="SearchResults"> |
| 142 | + |
| 143 | +### Source files that had search results |
| 144 | +**org.openrewrite.table.SearchResults** |
| 145 | + |
| 146 | +_Search results that were found during the recipe run._ |
| 147 | + |
| 148 | +| Column Name | Description | |
| 149 | +| ----------- | ----------- | |
| 150 | +| Source path of search result before the run | The source path of the file with the search result markers present. | |
| 151 | +| Source path of search result after run the run | A recipe may modify the source path. This is the path after the run. `null` when a source file was deleted during the run. | |
| 152 | +| Result | The trimmed printed tree of the LST element that the marker is attached to. | |
| 153 | +| Description | The content of the description of the marker. | |
| 154 | +| Recipe that added the search marker | The specific recipe that added the Search marker. | |
| 155 | + |
| 156 | +</TabItem> |
| 157 | + |
| 158 | +<TabItem value="org.openrewrite.table.SourcesFileErrors" label="SourcesFileErrors"> |
| 159 | + |
| 160 | +### Source files that errored on a recipe |
| 161 | +**org.openrewrite.table.SourcesFileErrors** |
| 162 | + |
| 163 | +_The details of all errors produced by a recipe run._ |
| 164 | + |
| 165 | +| Column Name | Description | |
| 166 | +| ----------- | ----------- | |
| 167 | +| Source path | The file that failed to parse. | |
| 168 | +| Recipe that made changes | The specific recipe that made a change. | |
| 169 | +| Stack trace | The stack trace of the failure. | |
| 170 | + |
| 171 | +</TabItem> |
| 172 | + |
| 173 | +<TabItem value="org.openrewrite.table.RecipeRunStats" label="RecipeRunStats"> |
| 174 | + |
| 175 | +### Recipe performance |
| 176 | +**org.openrewrite.table.RecipeRunStats** |
| 177 | + |
| 178 | +_Statistics used in analyzing the performance of recipes._ |
| 179 | + |
| 180 | +| Column Name | Description | |
| 181 | +| ----------- | ----------- | |
| 182 | +| The recipe | The recipe whose stats are being measured both individually and cumulatively. | |
| 183 | +| Source file count | The number of source files the recipe ran over. | |
| 184 | +| Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. | |
| 185 | +| Cumulative scanning time (ns) | The total time spent across the scanning phase of this recipe. | |
| 186 | +| Max scanning time (ns) | The max time scanning any one source file. | |
| 187 | +| Cumulative edit time (ns) | The total time spent across the editing phase of this recipe. | |
| 188 | +| Max edit time (ns) | The max time editing any one source file. | |
| 189 | + |
| 190 | +</TabItem> |
| 191 | + |
| 192 | +</Tabs> |
0 commit comments