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 all commits
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
50 changes: 40 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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')) {
AndreKurait marked this conversation as resolved.
Show resolved Hide resolved
fromResolutionOf('testFixturesRuntimeClasspath')
}
fromResolutionResult()
}
}
Expand All @@ -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'
Expand All @@ -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')
Expand Down