Skip to content

Commit 5829976

Browse files
committed
For #505. Enable Enforcer for Gradle
There are caveats. The wiki page needs to discuss these.
1 parent f23a4e2 commit 5829976

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

build.gradle

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import com.github.spotbugs.snom.Confidence
33
import com.github.spotbugs.snom.Effort
44

55
plugins {
6-
alias libs.plugins.org.kordamp.gradle.project.enforcer
76
id "build-dashboard" // See build/reports/buildDashboard/index.html
87
// TODO: project-report is presently broken because of pitest task
98
id "project-report" // Try the `projectReport` task
@@ -26,16 +25,6 @@ plugins {
2625
version = "0-SNAPSHOT"
2726
group = "demo"
2827

29-
// Do read the documentation on Enforcer to pick what makes sense to you:
30-
// https://kordamp.org/enforcer-gradle-plugin/#_rule_dsl
31-
// TODO: Follow-up with plugin GitHub: https://github.com/kordamp/enforcer-gradle-plugin/issues/17#issuecomment-2169301864
32-
/*
33-
enforce {
34-
configure()
35-
rule()
36-
}
37-
*/
38-
3928
repositories {
4029
mavenCentral()
4130
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ checkstyleVersion=10.17.0
55
coverageBranches=1.00
66
coverageInstructions=1.00
77
coverageLines=1.00
8+
enforcerPluginVersion=0.13.0
89
findsecbugsPluginVersion=1.13.0
910
# Hey! This is important. This property sets your Gradle version.
1011
gradleWrapperVersion=8.9

gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ org-gaul-modernizer = "2.9.0"
1010
org-jacoco = "0.8.12"
1111
org-junit-jupiter = "5.11.0-RC1"
1212
org-kordamp-gradle-jdeps-plugin = "0.20.0"
13-
org-kordamp-gradle-project-enforcer-plugin = "0.13.0"
1413
org-mockito = "5.12.0"
1514
org-owasp-dependencycheck-plugin = "10.0.3"
1615
org-pitest-pitest-command-line = "1.16.1"
@@ -41,6 +40,5 @@ com-dorongold-task-tree = { id = "com.dorongold.task-tree", version.ref = "com-d
4140
com-github-andygoossens-gradle-modernizer-plugin = { id = "com.github.andygoossens.gradle-modernizer-plugin", version.ref = "com-github-andygoossens-gradle-modernizer-plugin" }
4241
com-github-ben-manes-versions = { id = "com.github.ben-manes.versions", version.ref = "com-github-ben-manes-versions-plugin" }
4342
org-kordamp-gradle-jdeps = { id = "org.kordamp.gradle.jdeps", version.ref = "org-kordamp-gradle-jdeps-plugin" }
44-
org-kordamp-gradle-project-enforcer = { id = "org.kordamp.gradle.project-enforcer", version.ref = "org-kordamp-gradle-project-enforcer-plugin" }
4543
org-owasp-dependencycheck = { id = "org.owasp.dependencycheck", version.ref = "org-owasp-dependencycheck-plugin" }
4644
nl-littlerobots-version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "nl-littlerobots-version-catalog-update-plugin" }

settings.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
1+
// Note:
2+
// When you see "$fooVersion", those are versions pulled from
3+
// "gradle.properties".
4+
5+
// TODO: Migrate these to use the version catalog (like other plugins in
6+
// "build.gradle").
17
pluginManagement {
28
plugins {
39
id "com.github.spotbugs" version "$spotbugsPluginVersion"
410
id "info.solidsoft.pitest" version "$pitestPluginVersion"
511
}
612
}
713

14+
buildscript {
15+
repositories {
16+
gradlePluginPortal()
17+
mavenCentral()
18+
}
19+
20+
dependencies {
21+
// Enforcer plugin uses an older version of commons-lang3 that breaks
22+
// DependencyCheck. Force a current version.
23+
// TODO: Look for an updated Enforcer plugin that does not clash.
24+
classpath "org.apache.commons:commons-lang3:3.15.0"
25+
classpath "org.kordamp.gradle:enforcer-gradle-plugin:$enforcerPluginVersion"
26+
}
27+
}
28+
29+
apply plugin: "org.kordamp.gradle.enforcer"
30+
31+
// See https://kordamp.org/enforcer-gradle-plugin/#_rules for the kinds of
32+
// rules you can set up.
33+
enforce {
34+
rule(enforcer.rules.RequireGradleVersion) { r ->
35+
r.version = "$gradleWrapperVersion"
36+
}
37+
}
38+
839
rootProject.name = "modern-java-practices"

0 commit comments

Comments
 (0)