diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index 9402462eb7..806c4f2095 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -53,10 +53,13 @@ dependencies { val defaultScalaVersion: String = project.findProperty("defaultScalaVersion")!!.toString() val scalaVersions: List? = project.findProperty("supportedScalaVersions")?.toString()?.split(",") -assert(!scalaVersions.isNullOrEmpty()) { +require(!scalaVersions.isNullOrEmpty()) { "Scala versions must be provided as a comma-separated list in the 'supportedScalaVersions' project property" } +scalaVersions?.forEach { version -> + require(version.matches(Regex("\\d\\.\\d{2}"))) { "Scala version '$version' must be in the format X.YY" } +} /* * Apply the Java Platform plugin to create the BOM * Modify the generated POM to include all supported versions of Scala for driver-scala or bson-scala. @@ -73,14 +76,14 @@ configureMavenPublication { val pomXml: Node = asNode() val dependencyManagementNode = pomXml.getNode("dependencyManagement") - assert(dependencyManagementNode != null) { + require(dependencyManagementNode != null) { " node not found in the generated BOM POM" } val dependenciesNode = dependencyManagementNode.getNode("dependencies") - assert(dependenciesNode != null) { " node not found in the generated BOM POM" } + require(dependenciesNode != null) { " node not found in the generated BOM POM" } val existingScalaDeps = - dependenciesNode!! + dependenciesNode .children() .map { it as Node } .filter { it.getNode("artifactId")?.text()?.contains("scala") ?: false } @@ -110,37 +113,35 @@ configureMavenPublication { * Validate the BOM file. */ tasks.withType { - doLast { - pom.withXml { - val pomXml: Node = asNode() - val dependenciesNode = pomXml.getNode("dependencyManagement").getNode("dependencies") - assert(dependenciesNode!!.children().isNotEmpty()) { - "BOM must contain more then one element:\n$destination" - } + pom.withXml { + val pomXml: Node = asNode() + val dependenciesNode = pomXml.getNode("dependencyManagement").getNode("dependencies") + require(dependenciesNode!!.children().isNotEmpty()) { + "BOM must contain more then one element:\n$destination" + } - dependenciesNode - .children() - .map { it as Node } - .forEach { - val groupId: String = it.getNode("groupId")!!.text() - assert(groupId.startsWith("org.mongodb")) { - "BOM must contain only 'org.mongodb' dependencies, but found '$groupId':\n$destination" - } + dependenciesNode + .children() + .map { it as Node } + .forEach { + val groupId: String = it.getNode("groupId")!!.text() + require(groupId.startsWith("org.mongodb")) { + "BOM must contain only 'org.mongodb' dependencies, but found '$groupId':\n$destination" + } - /* - * The and tags should be omitted in BOM dependencies. - * This ensures that consuming projects have the flexibility to decide whether a dependency is optional in their context. - * - * The BOM's role is to provide version information, not to dictate inclusion or exclusion of dependencies. - */ - assert(it.getNode("scope") == null) { - "BOM must not contain elements in dependency:\n$destination" - } - assert(it.getNode("optional") == null) { - "BOM must not contain elements in dependency:\n$destination" - } + /* + * The and tags should be omitted in BOM dependencies. + * This ensures that consuming projects have the flexibility to decide whether a dependency is optional in their context. + * + * The BOM's role is to provide version information, not to dictate inclusion or exclusion of dependencies. + */ + require(it.getNode("scope") == null) { + "BOM must not contain elements in dependency:\n$destination" } - } + require(it.getNode("optional") == null) { + "BOM must not contain elements in dependency:\n$destination" + } + } } }