Skip to content

Commit

Permalink
Remove unspecified dependencies in maven pom publishing
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait committed Oct 23, 2024
1 parent db0075e commit ab1ead8
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id "com.diffplug.spotless" version '6.25.0'
id 'me.champeau.jmh' version '0.7.2' apply false
id 'jacoco'
id 'java-test-fixtures'
}

allprojects {
Expand All @@ -13,6 +14,21 @@ 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
group = 'org.opensearch.migrations.trafficcapture' // Ensure groupId is consistent
}

subprojects { subproject ->
subproject.afterEvaluate {
if (subproject.plugins.hasPlugin('java') && subproject.name != 'commonDependencyVersionConstraints') {
Expand Down Expand Up @@ -157,6 +173,9 @@ subprojects {
mavenJava(MavenPublication) {
versionMapping {
allVariants {
if (project.plugins.hasPlugin('java-test-fixtures')) {
fromResolutionOf('testFixturesRuntimeClasspath')
}
fromResolutionResult()
}
}
Expand All @@ -165,16 +184,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'
Expand All @@ -199,6 +208,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')
Expand Down

0 comments on commit ab1ead8

Please sign in to comment.