Skip to content

Commit aa6a655

Browse files
committed
Add logic to map nvd api key to dependency check tasks
1 parent 5e3c09f commit aa6a655

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/main/java/uk/gov/hmcts/tools/DependencyCheckSetup.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ public static void apply(Project project) {
3636
project.getPlugins().apply(DependencyCheckPlugin.class);
3737

3838
DependencyCheckExtension extension = project.getExtensions().getByType(DependencyCheckExtension.class);
39+
40+
Project root = project.getRootProject();
41+
42+
// Gradle property: -PdependencyCheck.nvd.apiKey=...
43+
String apiKey = (String) root.findProperty("dependencyCheck.nvd.apiKey");
44+
45+
// JVM system property: -DdependencyCheck.nvd.apiKey=...
46+
if (apiKey == null || apiKey.isBlank()) {
47+
apiKey = System.getProperty("dependencyCheck.nvd.apiKey");
48+
}
49+
50+
// Environment variable
51+
if (apiKey == null || apiKey.isBlank()) {
52+
apiKey = System.getenv("NVD_API_KEY");
53+
}
54+
55+
if (apiKey != null && !apiKey.isBlank()) {
56+
extension.getNvd().setApiKey(apiKey);
57+
}
58+
3959
extension.setFailBuildOnCVSS(0f);
4060

4161
// Match the CNP pipeline which disables these checks

0 commit comments

Comments
 (0)