Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unspecified dependencies in maven pom publishing #1100

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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
AndreKurait marked this conversation as resolved.
Show resolved Hide resolved
}

subprojects { subproject ->
subproject.afterEvaluate {
if (subproject.plugins.hasPlugin('java') && subproject.name != 'commonDependencyVersionConstraints') {
Expand Down Expand Up @@ -157,6 +172,9 @@ subprojects {
mavenJava(MavenPublication) {
versionMapping {
allVariants {
if (project.plugins.hasPlugin('java-test-fixtures')) {
AndreKurait marked this conversation as resolved.
Show resolved Hide resolved
fromResolutionOf('testFixturesRuntimeClasspath')
}
fromResolutionResult()
}
}
Expand All @@ -165,16 +183,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 +207,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