diff --git a/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy b/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy index c861588e1e364..d17f16ca5ed93 100644 --- a/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy +++ b/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy @@ -771,10 +771,11 @@ class BeamModulePlugin implements Plugin { // Create a task which emulates the maven-archiver plugin in generating a // pom.properties file. + def pomPropertiesFile = "${project.buildDir}/publications/mavenJava/pom.properties" project.task('generatePomPropertiesFileForMavenJavaPublication') { - outputs.file "${project.buildDir}/publications/mavenJava/pom.properties" + outputs.file "${pomPropertiesFile}" doLast { - new File("${project.buildDir}/publications/mavenJava/pom.properties").text = + new File("${pomPropertiesFile}").text = """version=${project.version} groupId=${project.group} artifactId=${project.name} @@ -785,10 +786,23 @@ artifactId=${project.name} // Have the shaded include both the generate pom.xml and its properties file // emulating the behavior of the maven-archiver plugin. project.shadowJar { + def pomFile = "${project.buildDir}/publications/mavenJava/pom-default.xml" + + // Validate that the artifacts exist before copying them into the jar. + doFirst { + if (!project.file("${pomFile}").exists()) { + throw new GradleException("Expected ${pomFile} to have been generated by the 'generatePomFileForMavenJavaPublication' task.") + } + if (!project.file("${pomPropertiesFile}").exists()) { + throw new GradleException("Expected ${pomPropertiesFile} to have been generated by the 'generatePomPropertiesFileForMavenJavaPublication' task.") + } + } + dependsOn 'generatePomFileForMavenJavaPublication' - into("META-INF/maven/${project.group}/${project.name}") { from "${project.buildDir}/publications/mavenJava/pom.xml" } + into("META-INF/maven/${project.group}/${project.name}") { from "${pomFile}" } + dependsOn project.generatePomPropertiesFileForMavenJavaPublication - into("META-INF/maven/${project.group}/${project.name}") { from "${project.buildDir}/publications/mavenJava/pom.properties" } + into("META-INF/maven/${project.group}/${project.name}") { from "${pomPropertiesFile}" } } // Only build artifacts for archives if we are publishing