You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+74-2
Original file line number
Diff line number
Diff line change
@@ -57,14 +57,14 @@ Gradle can be used to build projects developed in various programming languages.
57
57
58
58
```
59
59
plugins {
60
-
id 'org.sonatype.gradle.plugins.scan' version '2.5.4' // Update the version as needed
60
+
id 'org.sonatype.gradle.plugins.scan' version '2.5.5' // Update the version as needed
61
61
}
62
62
```
63
63
64
64
- Or `build.gradle.kts`:
65
65
```
66
66
plugins {
67
-
id ("org.sonatype.gradle.plugins.scan") version "2.5.4" // Update the version as needed
67
+
id ("org.sonatype.gradle.plugins.scan") version "2.5.5" // Update the version as needed
68
68
}
69
69
```
70
70
@@ -96,6 +96,9 @@ ossIndexAudit {
96
96
modulesIncluded = ['module-1', 'module-2'] // Optional. For multi-module projects, the names of the sub-modules to include for auditing. If not specified all modules are included.
97
97
modulesExcluded = ['module-1', 'module-2'] // Optional. For multi-module projects, the names of the sub-modules to exclude from auditing. If not specified no modules are excluded. This value is processed after 'modulesIncluded' if both are specified.
98
98
99
+
// For projects using multiple custom variants for the release distribution, a Map can be set with the attributes names and values to match the specific variant. See more at the section "How to Deal with Multiple Release Variants" below in this doc.
100
+
variantAttributes = ['com.android.build.api.attributes.ProductFlavor:version': 'prod', 'other.attribute': 'other value'] // Optional, use it only when the plugin can't match a variant on its own
101
+
99
102
// ossIndexAudit can be configured to exclude vulnerabilities from matching
100
103
excludeVulnerabilityIds = ['39d74cc8-457a-4e57-89ef-a258420138c5'] // list containing ids of vulnerabilities to be ignored
101
104
excludeCoordinates = ['commons-fileupload:commons-fileupload:1.3'] // list containing coordinate of components which if vulnerable should be ignored
@@ -130,6 +133,9 @@ ossIndexAudit {
130
133
modulesIncluded =listOf("module-1", "module-2") // Optional. For multi-module projects, the names of the sub-modules to include for auditing. If not specified all modules are included.
131
134
modulesExcluded =listOf("module-1", "module-2") // Optional. For multi-module projects, the names of the sub-modules to exclude from auditing. If not specified no modules are excluded. This value is processed after 'modulesIncluded' if both are specified.
132
135
136
+
// For projects using multiple custom variants for the release distribution, a Map can be set with the attributes names and values to match the specific variant. See more at the section "How to Deal with Multiple Release Variants" below in this doc.
137
+
variantAttributes =mapOf("com.android.build.api.attributes.ProductFlavor:version" to "prod", "other.attribute" to "other value") // Optional, use it only when the plugin can't match a variant on its own
138
+
133
139
// ossIndexAudit can be configured to exclude vulnerabilities from matching
134
140
excludeVulnerabilityIds =
135
141
listOf("39d74cc8-457a-4e57-89ef-a258420138c5") // list containing ids of vulnerabilities to be ignored
@@ -166,6 +172,9 @@ nexusIQScan {
166
172
modulesExcluded = ['module-1', 'module-2'] // Optional. For multi-module projects, the names of the sub-modules to exclude from scanning and evaluation.
167
173
dirExcludes = 'some-ant-pattern' // Optional. Comma separated ant-like glob patterns to select directories/archives that should be excluded. For Android projects we suggest using '**/classes.jar,**/annotations.zip,**/lint.jar,**/internal_impl-*.jar'
168
174
dirIncludes = 'some-ant-pattern' // Optional. Comma separated ant-like glob patterns to select directories/archives that should be examined
175
+
176
+
// For projects using multiple custom variants for the release distribution, a Map can be set with the attributes names and values to match the specific variant. See more at the section "How to Deal with Multiple Release Variants" below in this doc.
177
+
variantAttributes = ['com.android.build.api.attributes.ProductFlavor:version': 'prod', 'other.attribute': 'other value'] // Optional, use it only when the plugin can't match a variant on its own
169
178
}
170
179
```
171
180
@@ -183,6 +192,9 @@ nexusIQScan {
183
192
modulesExcluded = listOf("module-1", "module-2") // Optional. For multi-module projects, the names of the sub-modules to exclude from scanning and evaluation.
184
193
dirExcludes = "some-ant-pattern" // Optional. Comma separated ant-like glob patterns to select directories/archives that should be excluded. For Android projects we suggest using "**/classes.jar,**/annotations.zip,**/lint.jar,**/internal_impl-*.jar"
185
194
dirIncludes = "some-ant-pattern" // Optional. Comma separated ant-like glob patterns to select directories/archives that should be examined
195
+
196
+
// For projects using multiple custom variants for the release distribution, a Map can be set with the attributes names and values to match the specific variant. See more at the section "How to Deal with Multiple Release Variants" below in this doc.
197
+
variantAttributes = mapOf("com.android.build.api.attributes.ProductFlavor:version" to "prod", "other.attribute" to "other value") // Optional, use it only when the plugin can't match a variant on its own
186
198
}
187
199
```
188
200
@@ -306,6 +318,66 @@ ossIndexAudit {
306
318
Just apply the plugin on the root project and all sub-modules will be processed and the output will be a single report
307
319
with all components found in each module. This includes Android projects.
308
320
321
+
## How to Deal with Multiple Release Variants
322
+
This plugin makes its best effort to find the release (production) configuration and variant to get the dependencies to analyze.
323
+
324
+
However, a Gradle project can have multiple custom release variants and the plugin might not be able to tell Gradle which one to pick, resulting in an error like this:
325
+
326
+
```
327
+
> Could not resolve all dependencies for configuration 'sonatypeCopyConfiguration0'.
328
+
> Could not resolve project :common-lib.
329
+
Required by:
330
+
project :app
331
+
> The consumer was configured to find a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release'. However we cannot choose between the following variants of project :baseapp:
332
+
- ciReleaseRuntimeElements
333
+
- prodReleaseRuntimeElements
334
+
All of them match the consumer attributes:
335
+
- Variant 'ciReleaseRuntimeElements' capability common-lib:1.0.0 declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release':
336
+
- Unmatched attributes:
337
+
- Provides attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.2' but the consumer didn't ask for it
338
+
- Provides attribute 'com.android.build.api.attributes.ProductFlavor:version' with value 'ci' but the consumer didn't ask for it
339
+
- Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'ciRelease' but the consumer didn't ask for it
340
+
- Provides a library but the consumer didn't ask for it
341
+
- Provides attribute 'org.gradle.jvm.environment' with value 'android' but the consumer didn't ask for it
342
+
- Variant 'prodReleaseRuntimeElements' capability common-lib:1.0.0 declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release':
343
+
- Unmatched attributes:
344
+
- Provides attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.2' but the consumer didn't ask for it
345
+
- Provides attribute 'com.android.build.api.attributes.ProductFlavor:version' with value 'prod' but the consumer didn't ask for it
346
+
- Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'prodRelease' but the consumer didn't ask for it
347
+
- Provides a library but the consumer didn't ask for it
348
+
- Provides attribute 'org.gradle.jvm.environment' with value 'android' but the consumer didn't ask for it
349
+
```
350
+
351
+
From that output we can see the value of the attribute `com.android.build.api.attributes.ProductFlavor:version` can be used to distinguish between the available variants.
352
+
353
+
Since attribute names and values can be customized on each project, this plugin allows to set the attributes needed to match the right variant using the property `variantAttributes`.
354
+
355
+
In the example above, the following configuration would allow the plugin to choose the `prodReleaseRuntimeElements` variant:
variantAttributes = mapOf("com.android.build.api.attributes.ProductFlavor:version" to "prod")
372
+
}
373
+
374
+
ossIndexAudit {
375
+
variantAttributes = mapOf("com.android.build.api.attributes.ProductFlavor:version" to "prod")
376
+
}
377
+
```
378
+
379
+
See more information about attributes matching for variant selection see https://docs.gradle.org/current/userguide/variant_model.html#sec:variant-select-errors
380
+
309
381
## Contributing
310
382
311
383
We care a lot about making the world a safer place, and that's why we created this `scan-gradle-plugin`. If you as well want to speed up the pace of software development by working on this project, jump on in! Before you start work, create a new issue, or comment on an existing issue, to let others know you are!
0 commit comments