Skip to content

[SPARK-43646][PROTOBUF][BUILD] Split protobuf-assembly module from protobuf module #41466

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

Closed
wants to merge 12 commits into from
90 changes: 90 additions & 0 deletions connector/protobuf-assembly/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.spark</groupId>
<artifactId>spark-parent_2.12</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>spark-protobuf-assembly_2.12</artifactId>
<properties>
<sbt.project.name>protobuf-assembly</sbt.project.name>
</properties>
<packaging>jar</packaging>
<name>Spark Protobuf Assembly</name>
<url>https://spark.apache.org/</url>

<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-protobuf_${scala.binary.version}</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>
<testOutputDirectory>target/scala-${scala.binary.version}/test-classes</testOutputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<shadeTestJar>false</shadeTestJar>
<artifactSet>
<includes>
<include>org.apache.spark:spark-protobuf_${scala.binary.version}</include>
<include>com.google.protobuf:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.google.protobuf</pattern>
<shadedPattern>${spark.shade.packageName}.spark_protobuf.protobuf</shadedPattern>
<includes>
<include>com.google.protobuf.**</include>
</includes>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>google/protobuf/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</build>
</project>
32 changes: 0 additions & 32 deletions connector/protobuf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,38 +90,6 @@
<build>
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>
<testOutputDirectory>target/scala-${scala.binary.version}/test-classes</testOutputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<shadeTestJar>false</shadeTestJar>
<artifactSet>
<includes>
<include>com.google.protobuf:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.google.protobuf</pattern>
<shadedPattern>${spark.shade.packageName}.spark_protobuf.protobuf</shadedPattern>
<includes>
<include>com.google.protobuf.**</include>
</includes>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>google/protobuf/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<module>connector/connect/common</module>
<module>connector/connect/client/jvm</module>
<module>connector/protobuf</module>
<module>connector/protobuf-assembly</module>
<!-- See additional modules enabled by profiles below -->
</modules>

Expand Down
53 changes: 34 additions & 19 deletions project/SparkBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ object BuildCommons {

private val buildLocation = file(".").getAbsoluteFile.getParentFile

val sqlProjects@Seq(catalyst, sql, hive, hiveThriftServer, tokenProviderKafka010, sqlKafka010, avro, protobuf) = Seq(
"catalyst", "sql", "hive", "hive-thriftserver", "token-provider-kafka-0-10", "sql-kafka-0-10", "avro", "protobuf"
val sqlProjects@Seq(catalyst, sql, hive, hiveThriftServer,
tokenProviderKafka010, sqlKafka010, avro, protobuf, protobufAssembly) = Seq(
"catalyst", "sql", "hive", "hive-thriftserver", "token-provider-kafka-0-10", "sql-kafka-0-10", "avro",
"protobuf", "protobuf-assembly"
).map(ProjectRef(buildLocation, _))

val streamingProjects@Seq(streaming, streamingKafka010) =
Expand Down Expand Up @@ -414,7 +416,7 @@ object SparkBuild extends PomBuild {
Seq(
spark, hive, hiveThriftServer, repl, networkCommon, networkShuffle, networkYarn,
unsafe, tags, tokenProviderKafka010, sqlKafka010, connectCommon, connect, connectClient,
commonUtils, sqlApi
commonUtils, sqlApi, protobufAssembly
).contains(x)
}

Expand Down Expand Up @@ -463,6 +465,7 @@ object SparkBuild extends PomBuild {

/* Protobuf settings */
enable(SparkProtobuf.settings)(protobuf)
enable(SparkProtobufAssembly.settings)(protobufAssembly)

// SPARK-14738 - Remove docker tests from main Spark build
// enable(DockerIntegrationTests.settings)(dockerIntegrationTests)
Expand Down Expand Up @@ -957,10 +960,34 @@ object SparkProtobuf {
PB.gens.descriptorSet -> target.value / "generated-test-sources/descriptor-set-sbt.desc",
// The above creates single descriptor file with all the proto files. This is different from
// Maven, which create one descriptor file for each proto file.
),
)
) ++ {
val sparkProtocExecPath = sys.props.get("spark.protoc.executable.path")
if (sparkProtocExecPath.isDefined) {
Seq(
PB.protocExecutable := file(sparkProtocExecPath.get)
)
} else {
Seq.empty
}
}
}

object SparkProtobufAssembly {
import BuildCommons.protoVersion

lazy val settings = Seq(
// For some reason the resolution from the imported Maven build does not work for some
// of these dependendencies that we need to shade later on.
libraryDependencies += "com.google.protobuf" % "protobuf-java" % protoVersion % "protobuf",

dependencyOverrides += "com.google.protobuf" % "protobuf-java" % protoVersion,

(assembly / test) := { },

(assembly / assemblyJarName) :=
s"spark-protobuf-assembly_${scalaBinaryVersion.value}-${version.value}.jar",

(assembly / logLevel) := Level.Info,

// Exclude `scala-library` from assembly.
Expand All @@ -978,25 +1005,17 @@ object SparkProtobuf {
},

(assembly / assemblyShadeRules) := Seq(
ShadeRule.rename("com.google.protobuf.**" -> "org.sparkproject.spark_protobuf.protobuf.@1").inAll,
ShadeRule.rename(
"com.google.protobuf.**" -> "org.sparkproject.spark_protobuf.protobuf.@1").inAll,
),

(assembly / assemblyMergeStrategy) := {
case m if m.toLowerCase(Locale.ROOT).endsWith("manifest.mf") => MergeStrategy.discard
// Drop all proto files that are not needed as artifacts of the build.
case m if m.toLowerCase(Locale.ROOT).endsWith(".proto") => MergeStrategy.discard
case _ => MergeStrategy.first
},
) ++ {
val sparkProtocExecPath = sys.props.get("spark.protoc.executable.path")
if (sparkProtocExecPath.isDefined) {
Seq(
PB.protocExecutable := file(sparkProtocExecPath.get)
)
} else {
Seq.empty
}
}
)
}

object Unsafe {
Expand Down Expand Up @@ -1535,7 +1554,6 @@ object CopyDependencies {
// Later, when the dependencies are copied, we manually copy the shaded Jar only.
val fid = (LocalProject("connect") / assembly).value
val fidClient = (LocalProject("connect-client-jvm") / assembly).value
val fidProtobuf = (LocalProject("protobuf") / assembly).value

(Compile / dependencyClasspath).value.map(_.data)
.filter { jar => jar.isFile() }
Expand All @@ -1551,9 +1569,6 @@ object CopyDependencies {
} else if (jar.getName.contains("connect-client-jvm") &&
!SbtPomKeys.profiles.value.contains("noshade-connect-client-jvm")) {
Files.copy(fidClient.toPath, destJar.toPath)
} else if (jar.getName.contains("spark-protobuf") &&
!SbtPomKeys.profiles.value.contains("noshade-protobuf")) {
Files.copy(fidProtobuf.toPath, destJar.toPath)
} else {
Files.copy(jar.toPath(), destJar.toPath())
}
Expand Down