diff --git a/build.gradle b/build.gradle index 03ffc44f4..a0bc213c7 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,22 @@ allprojects { } } +// Define version properties +ext { + // support -Dbuild.version, but include default + buildVersion = System.getProperty("build.version", "0.1.0") + // support -Dbuild.snapshot=false, but default to true + buildSnapshot = System.getProperty("build.snapshot", "true") == "true" + finalVersion = buildSnapshot ? "${buildVersion}-SNAPSHOT" : buildVersion +} + +// Apply the version to all projects +allprojects { + version = finalVersion + // This should eventually change, see https://opensearch.atlassian.net/browse/MIGRATIONS-2167 + group = 'org.opensearch.migrations.trafficcapture' +} + subprojects { subproject -> subproject.afterEvaluate { if (subproject.plugins.hasPlugin('java') && subproject.name != 'commonDependencyVersionConstraints') { @@ -157,6 +173,12 @@ subprojects { mavenJava(MavenPublication) { versionMapping { allVariants { + // Test fixtures are published as a separate jar in maven + // This ensures dependencies that are only declared in test + // fixtures have a version number in the pom + if (project.plugins.hasPlugin('java-test-fixtures')) { + fromResolutionOf('testFixturesRuntimeClasspath') + } fromResolutionResult() } } @@ -165,16 +187,6 @@ subprojects { artifact javadocJar artifact sourcesJar - group = 'org.opensearch.migrations.trafficcapture' - - // support -Dbuild.version, but include default - version = System.getProperty("build.version", "0.1.0") - - // support -Dbuild.snapshot=false, but default to true - if (System.getProperty("build.snapshot", "true") == "true") { - version += "-SNAPSHOT" - } - pom { name = project.name description = 'Everything opensearch migrations' @@ -199,6 +211,24 @@ subprojects { } } + pom.withXml { + def pomFile = asNode() + + // Find all dependencies in the POM file + def dependencies = pomFile.dependencies.dependency + + // Iterate over each dependency and check if the version is missing + dependencies.each { dependency -> + def version = dependency.version.text() + + if (version == null || version.trim().isEmpty() || version.trim() == 'unspecified') { + def groupId = dependency.groupId.text() + def artifactId = dependency.artifactId.text() + throw new GradleException("Dependency ${groupId}:${artifactId} is missing a version in the pom.xml") + } + } + } + // Suppress POM metadata warnings for test fixtures suppressPomMetadataWarningsFor('testFixturesApiElements') suppressPomMetadataWarningsFor('testFixturesRuntimeElements')