Skip to content

Commit b9fec03

Browse files
committed
[BEAM-5351] Fix missing pom.xml file in artifact jar.
I also validate that the files exist and error out the build otherwise.
1 parent 883f015 commit b9fec03

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy

+18-4
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,11 @@ class BeamModulePlugin implements Plugin<Project> {
771771

772772
// Create a task which emulates the maven-archiver plugin in generating a
773773
// pom.properties file.
774+
def pomPropertiesFile = "${project.buildDir}/publications/mavenJava/pom.properties"
774775
project.task('generatePomPropertiesFileForMavenJavaPublication') {
775-
outputs.file "${project.buildDir}/publications/mavenJava/pom.properties"
776+
outputs.file "${pomPropertiesFile}"
776777
doLast {
777-
new File("${project.buildDir}/publications/mavenJava/pom.properties").text =
778+
new File("${pomPropertiesFile}").text =
778779
"""version=${project.version}
779780
groupId=${project.group}
780781
artifactId=${project.name}
@@ -785,10 +786,23 @@ artifactId=${project.name}
785786
// Have the shaded include both the generate pom.xml and its properties file
786787
// emulating the behavior of the maven-archiver plugin.
787788
project.shadowJar {
789+
def pomFile = "${project.buildDir}/publications/mavenJava/pom-default.xml"
790+
791+
// Validate that the artifacts exist before copying them into the jar.
792+
doFirst {
793+
if (!project.file("${pomFile}").exists()) {
794+
throw new GradleException("Expected ${pomFile} to have been generated by the 'generatePomFileForMavenJavaPublication' task.")
795+
}
796+
if (!project.file("${pomPropertiesFile}").exists()) {
797+
throw new GradleException("Expected ${pomPropertiesFile} to have been generated by the 'generatePomPropertiesFileForMavenJavaPublication' task.")
798+
}
799+
}
800+
788801
dependsOn 'generatePomFileForMavenJavaPublication'
789-
into("META-INF/maven/${project.group}/${project.name}") { from "${project.buildDir}/publications/mavenJava/pom.xml" }
802+
into("META-INF/maven/${project.group}/${project.name}") { from "${pomFile}" }
803+
790804
dependsOn project.generatePomPropertiesFileForMavenJavaPublication
791-
into("META-INF/maven/${project.group}/${project.name}") { from "${project.buildDir}/publications/mavenJava/pom.properties" }
805+
into("META-INF/maven/${project.group}/${project.name}") { from "${pomPropertiesFile}" }
792806
}
793807

794808
// Only build artifacts for archives if we are publishing

0 commit comments

Comments
 (0)