Skip to content

Commit 010eb17

Browse files
authored
Added OWASP Dependency Check conventions and updated to latest dependencies (#2)
1 parent 97acd1b commit 010eb17

3 files changed

Lines changed: 55 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Features:
1111
- SpotBugs (HTML reports, shared exclude filter)
1212
- Checkstyle (10.12.4, project-relative config)
1313
- Gradle Versions plugin
14+
- OWASP Dependency Check conventions
1415
- GraalVM Native plugin (FormKiQ)
1516
- Repositories: `mavenLocal`, `mavenCentral`, Sonatype snapshots (optional)
1617

build.gradle

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
plugins {
22
id 'java-gradle-plugin'
3-
id "com.gradle.plugin-publish" version "2.0.0"
4-
id 'com.diffplug.spotless' version '7.2.1'
3+
id "com.gradle.plugin-publish" version "2.1.0"
4+
id 'com.diffplug.spotless' version '8.3.0'
5+
id 'org.owasp.dependencycheck' version '12.2.0'
6+
id "com.github.ben-manes.versions" version "0.53.0"
57
}
68

79
group 'com.formkiq.gradle'
8-
version '1.0.8'
10+
version '1.0.9'
911

1012
allprojects {
1113
apply plugin: 'com.diffplug.spotless'
@@ -17,14 +19,15 @@ repositories {
1719
}
1820

1921
dependencies {
20-
implementation 'com.github.spotbugs:com.github.spotbugs.gradle.plugin:6.4.1'
21-
implementation 'com.diffplug.spotless:com.diffplug.spotless.gradle.plugin:7.2.1'
22-
implementation 'com.github.ben-manes.versions:com.github.ben-manes.versions.gradle.plugin:0.52.0'
23-
implementation 'com.formkiq.gradle.graalvm-native-plugin:com.formkiq.gradle.graalvm-native-plugin.gradle.plugin:1.7.6'
22+
implementation 'com.github.spotbugs:com.github.spotbugs.gradle.plugin:6.4.8'
23+
implementation 'com.diffplug.spotless:com.diffplug.spotless.gradle.plugin:8.3.0'
24+
implementation 'com.github.ben-manes.versions:com.github.ben-manes.versions.gradle.plugin:0.53.0'
25+
implementation 'com.formkiq.gradle.graalvm-native-plugin:com.formkiq.gradle.graalvm-native-plugin.gradle.plugin:1.7.7'
26+
implementation 'org.owasp.dependencycheck:org.owasp.dependencycheck.gradle.plugin:12.2.0'
2427

2528
// can use for local graalvm.native-plugin use
26-
// implementation "com.formkiq.gradle:graalvm-native-plugin:1.7.6"
27-
testImplementation platform("org.spockframework:spock-bom:2.3-groovy-4.0")
29+
// implementation "com.formkiq.gradle:graalvm-native-plugin:1.7.7"
30+
testImplementation platform("org.spockframework:spock-bom:2.4-groovy-5.0")
2831
testImplementation 'org.spockframework:spock-core'
2932
}
3033

src/main/java/com/formkiq/gradle/JavaBasePlugin.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
import org.gradle.api.tasks.compile.JavaCompile;
1111
import org.gradle.api.tasks.testing.Test;
1212
import org.gradle.jvm.toolchain.JavaLanguageVersion;
13+
import org.owasp.dependencycheck.gradle.extension.AnalyzerExtension;
14+
import org.owasp.dependencycheck.gradle.extension.DependencyCheckExtension;
1315

16+
import java.util.Arrays;
17+
import java.util.List;
1418
import java.util.LinkedHashMap;
1519
import java.util.Map;
20+
import java.util.stream.Collectors;
1621

1722
/**
1823
* {@link Plugin} for FormKiQ Gradle Conventions.
@@ -36,6 +41,7 @@ public void apply(Project root) {
3641
p.getPluginManager().apply("checkstyle");
3742
p.getPluginManager().apply("com.github.spotbugs");
3843
p.getPluginManager().apply("com.github.ben-manes.versions");
44+
p.getPluginManager().apply("org.owasp.dependencycheck");
3945
p.getPluginManager().apply("com.formkiq.gradle.graalvm-native-plugin");
4046
p.getPluginManager().apply("distribution");
4147

@@ -105,6 +111,42 @@ public void apply(Project root) {
105111
cs.setMaxErrors(0);
106112
});
107113

114+
// OWASP Dependency Check
115+
p.getExtensions().configure(DependencyCheckExtension.class, dc -> {
116+
dc.setFormats(Arrays.asList("HTML", "JSON", "SARIF"));
117+
dc.setFailBuildOnCVSS(7.0f);
118+
dc.setScanConfigurations(Arrays.asList("runtimeClasspath"));
119+
dc.setSkipTestGroups(true);
120+
Object skipProjects = p.findProperty("dependencyCheckSkipProjects");
121+
if (skipProjects != null) {
122+
List<String> projectPaths = Arrays.stream(skipProjects.toString().split(","))
123+
.map(String::trim)
124+
.filter(s -> !s.isEmpty())
125+
.collect(Collectors.toList());
126+
dc.setSkipProjects(projectPaths);
127+
}
128+
dc.analyzers((AnalyzerExtension analyzers) -> {
129+
analyzers.getNodeAudit().setEnabled(false);
130+
analyzers.setOssIndexEnabled(true);
131+
analyzers.ossIndex(ossIndex -> {
132+
Object ossIndexUsername = p.findProperty("ossIndexUsername");
133+
if (ossIndexUsername != null) {
134+
ossIndex.setUsername(ossIndexUsername.toString());
135+
}
136+
137+
Object ossIndexPassword = p.findProperty("ossIndexPassword");
138+
if (ossIndexPassword != null) {
139+
ossIndex.setPassword(ossIndexPassword.toString());
140+
}
141+
});
142+
});
143+
144+
Object nvdKey = p.findProperty("nvdKey");
145+
if (nvdKey != null) {
146+
dc.nvd(nvd -> nvd.setApiKey(nvdKey.toString()));
147+
}
148+
});
149+
108150
// Compiler flags
109151
p.getTasks().withType(JavaCompile.class)
110152
.configureEach(jc -> jc.getOptions().getCompilerArgs().add("-Xlint:deprecation"));

0 commit comments

Comments
 (0)