@@ -53,10 +53,13 @@ dependencies {
53
53
val defaultScalaVersion: String = project.findProperty(" defaultScalaVersion" )!! .toString()
54
54
val scalaVersions: List <String >? = project.findProperty(" supportedScalaVersions" )?.toString()?.split(" ," )
55
55
56
- assert (! scalaVersions.isNullOrEmpty()) {
56
+ require (! scalaVersions.isNullOrEmpty()) {
57
57
" Scala versions must be provided as a comma-separated list in the 'supportedScalaVersions' project property"
58
58
}
59
59
60
+ scalaVersions?.forEach { version ->
61
+ require(version.matches(Regex (" \\ d\\ .\\ d{2}" ))) { " Scala version '$version ' must be in the format X.YY" }
62
+ }
60
63
/*
61
64
* Apply the Java Platform plugin to create the BOM
62
65
* Modify the generated POM to include all supported versions of Scala for driver-scala or bson-scala.
@@ -73,14 +76,14 @@ configureMavenPublication {
73
76
val pomXml: Node = asNode()
74
77
75
78
val dependencyManagementNode = pomXml.getNode(" dependencyManagement" )
76
- assert (dependencyManagementNode != null ) {
79
+ require (dependencyManagementNode != null ) {
77
80
" <dependencyManagement> node not found in the generated BOM POM"
78
81
}
79
82
val dependenciesNode = dependencyManagementNode.getNode(" dependencies" )
80
- assert (dependenciesNode != null ) { " <dependencies> node not found in the generated BOM POM" }
83
+ require (dependenciesNode != null ) { " <dependencies> node not found in the generated BOM POM" }
81
84
82
85
val existingScalaDeps =
83
- dependenciesNode!!
86
+ dependenciesNode
84
87
.children()
85
88
.map { it as Node }
86
89
.filter { it.getNode(" artifactId" )?.text()?.contains(" scala" ) ? : false }
@@ -110,37 +113,35 @@ configureMavenPublication {
110
113
* Validate the BOM file.
111
114
*/
112
115
tasks.withType<GenerateMavenPom > {
113
- doLast {
114
- pom.withXml {
115
- val pomXml: Node = asNode()
116
- val dependenciesNode = pomXml.getNode(" dependencyManagement" ).getNode(" dependencies" )
117
- assert (dependenciesNode!! .children().isNotEmpty()) {
118
- " BOM must contain more then one <dependency> element:\n $destination "
119
- }
116
+ pom.withXml {
117
+ val pomXml: Node = asNode()
118
+ val dependenciesNode = pomXml.getNode(" dependencyManagement" ).getNode(" dependencies" )
119
+ require(dependenciesNode!! .children().isNotEmpty()) {
120
+ " BOM must contain more then one <dependency> element:\n $destination "
121
+ }
120
122
121
- dependenciesNode
122
- .children()
123
- .map { it as Node }
124
- .forEach {
125
- val groupId: String = it.getNode(" groupId" )!! .text()
126
- assert (groupId.startsWith(" org.mongodb" )) {
127
- " BOM must contain only 'org.mongodb' dependencies, but found '$groupId ':\n $destination "
128
- }
123
+ dependenciesNode
124
+ .children()
125
+ .map { it as Node }
126
+ .forEach {
127
+ val groupId: String = it.getNode(" groupId" )!! .text()
128
+ require (groupId.startsWith(" org.mongodb" )) {
129
+ " BOM must contain only 'org.mongodb' dependencies, but found '$groupId ':\n $destination "
130
+ }
129
131
130
- /*
131
- * The <scope> and <optional> tags should be omitted in BOM dependencies.
132
- * This ensures that consuming projects have the flexibility to decide whether a dependency is optional in their context.
133
- *
134
- * The BOM's role is to provide version information, not to dictate inclusion or exclusion of dependencies.
135
- */
136
- assert (it.getNode(" scope" ) == null ) {
137
- " BOM must not contain <scope> elements in dependency:\n $destination "
138
- }
139
- assert (it.getNode(" optional" ) == null ) {
140
- " BOM must not contain <optional> elements in dependency:\n $destination "
141
- }
132
+ /*
133
+ * The <scope> and <optional> tags should be omitted in BOM dependencies.
134
+ * This ensures that consuming projects have the flexibility to decide whether a dependency is optional in their context.
135
+ *
136
+ * The BOM's role is to provide version information, not to dictate inclusion or exclusion of dependencies.
137
+ */
138
+ require(it.getNode(" scope" ) == null ) {
139
+ " BOM must not contain <scope> elements in dependency:\n $destination "
142
140
}
143
- }
141
+ require(it.getNode(" optional" ) == null ) {
142
+ " BOM must not contain <optional> elements in dependency:\n $destination "
143
+ }
144
+ }
144
145
}
145
146
}
146
147
0 commit comments