diff --git a/api/src/test/java/org/apache/iceberg/TestIcebergBuild.java b/api/src/test/java/org/apache/iceberg/TestIcebergBuild.java index 584bddb132d4..36ae9c90642c 100644 --- a/api/src/test/java/org/apache/iceberg/TestIcebergBuild.java +++ b/api/src/test/java/org/apache/iceberg/TestIcebergBuild.java @@ -19,7 +19,11 @@ package org.apache.iceberg; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assumptions.assumeThat; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Locale; import java.util.regex.Pattern; import org.junit.jupiter.api.Test; @@ -37,6 +41,34 @@ public void testFullVersion() { + ")"); } + @Test + public void testVersionNotUnspecified() { + assertThat(IcebergBuild.version()).isNotEqualTo("unspecified"); + } + + @Test + public void testVersionMatchesSystemProperty() { + assumeThat(System.getProperty("project.version")).isNotNull(); + assertThat(IcebergBuild.version()) + .isEqualTo(System.getProperty("project.version")) + .as("IcebergBuild.version() should match system property project.version"); + } + + /** + * This test is for Source Releases. When we have a source release we use a version.txt file in + * the parent directory of this module to actually set the "version" which should be included in + * the gradle build properties used by IcebergBuild. + */ + @Test + public void testVersionMatchesFile() throws IOException { + Path versionPath = Paths.get("../version.txt").toAbsolutePath(); + assumeThat(java.nio.file.Files.exists(versionPath)).isTrue(); + String versionText = java.nio.file.Files.readString(versionPath).trim(); + assertThat(IcebergBuild.version()) + .isEqualTo(versionText) + .as("IcebergBuild.version() should match version file"); + } + @Test public void testVersion() { assertThat(IcebergBuild.version()).as("Should not use unknown version").isNotEqualTo("unknown"); diff --git a/build.gradle b/build.gradle index 95b82f36301d..998f2ee9ea6d 100644 --- a/build.gradle +++ b/build.gradle @@ -95,6 +95,7 @@ gitProperties { failOnNoGitDirectory = true keys = ['git.branch', 'git.build.version', 'git.closest.tag.name','git.commit.id.abbrev', 'git.commit.id', 'git.commit.message.short', 'git.commit.time', 'git.tags'] + version = projectVersion } generateGitProperties.outputs.upToDateWhen { false } @@ -233,6 +234,8 @@ subprojects { events "failed" exceptionFormat "full" } + + systemProperty 'project.version', project.version } plugins.withType(ScalaPlugin.class) {