Skip to content

Commit fb13ecd

Browse files
committed
[SPARK-54847][BUILD] unify the proto/antlr output folder between sbt and maven
### What changes were proposed in this pull request? People may use sbt and maven together: local test with sbt, IDE with Maven. As of today this will trigger duplicated class issue during compilation, because sbt and Maven use different output folder for generated proto/antlr java classes. This PR updates the sbt build to use the same folder as Maven for proto/antlr output. ### Why are the changes needed? Improve dev experience. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Manual test ### Was this patch authored or co-authored using generative AI tooling? cursor 2.2.43 Closes #53616 from cloud-fan/shim. Lead-authored-by: Wenchen Fan <[email protected]> Co-authored-by: Wenchen Fan <[email protected]> Signed-off-by: Wenchen Fan <[email protected]> (cherry picked from commit 174b62d) Signed-off-by: Wenchen Fan <[email protected]>
1 parent 6d7ff76 commit fb13ecd

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

.sbtopts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
-J-Xmx8g
19+
-J-Xms8g
20+
-J-XX:MaxMetaspaceSize=1g

project/SparkBuild.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,10 @@ object Core {
646646
"com.google.protobuf" % "protobuf-java" % protoVersion % "protobuf"
647647
)
648648
},
649+
// Use Maven's output directory so sbt and Maven can share generated sources.
650+
// Core uses protoc-jar-maven-plugin which outputs to target/generated-sources.
649651
(Compile / PB.targets) := Seq(
650-
PB.gens.java -> (Compile / sourceManaged).value
652+
PB.gens.java -> target.value / "generated-sources"
651653
)
652654
) ++ {
653655
val sparkProtocExecPath = sys.props.get("spark.protoc.executable.path")
@@ -732,19 +734,20 @@ object SparkConnectCommon {
732734
) ++ {
733735
val sparkProtocExecPath = sys.props.get("spark.protoc.executable.path")
734736
val connectPluginExecPath = sys.props.get("connect.plugin.executable.path")
737+
// Use Maven's output directory so sbt and Maven can share generated sources
735738
if (sparkProtocExecPath.isDefined && connectPluginExecPath.isDefined) {
736739
Seq(
737740
(Compile / PB.targets) := Seq(
738-
PB.gens.java -> (Compile / sourceManaged).value,
739-
PB.gens.plugin(name = "grpc-java", path = connectPluginExecPath.get) -> (Compile / sourceManaged).value
741+
PB.gens.java -> target.value / "generated-sources" / "protobuf" / "java",
742+
PB.gens.plugin(name = "grpc-java", path = connectPluginExecPath.get) -> target.value / "generated-sources" / "protobuf" / "grpc-java"
740743
),
741744
PB.protocExecutable := file(sparkProtocExecPath.get)
742745
)
743746
} else {
744747
Seq(
745748
(Compile / PB.targets) := Seq(
746-
PB.gens.java -> (Compile / sourceManaged).value,
747-
PB.gens.plugin("grpc-java") -> (Compile / sourceManaged).value
749+
PB.gens.java -> target.value / "generated-sources" / "protobuf" / "java",
750+
PB.gens.plugin("grpc-java") -> target.value / "generated-sources" / "protobuf" / "grpc-java"
748751
)
749752
)
750753
}
@@ -1283,7 +1286,9 @@ object SqlApi {
12831286
(Antlr4 / antlr4PackageName) := Some("org.apache.spark.sql.catalyst.parser"),
12841287
(Antlr4 / antlr4GenListener) := true,
12851288
(Antlr4 / antlr4GenVisitor) := true,
1286-
(Antlr4 / antlr4TreatWarningsAsErrors) := true
1289+
(Antlr4 / antlr4TreatWarningsAsErrors) := true,
1290+
// Use Maven's output directory so sbt and Maven can share generated sources
1291+
(Antlr4 / javaSource) := target.value / "generated-sources" / "antlr4"
12871292
)
12881293
}
12891294

@@ -1300,8 +1305,10 @@ object SQL {
13001305
"com.google.protobuf" % "protobuf-java" % protoVersion % "protobuf"
13011306
)
13021307
},
1308+
// Use Maven's output directory so sbt and Maven can share generated sources.
1309+
// sql/core uses protoc-jar-maven-plugin which outputs to target/generated-sources.
13031310
(Compile / PB.targets) := Seq(
1304-
PB.gens.java -> (Compile / sourceManaged).value
1311+
PB.gens.java -> target.value / "generated-sources"
13051312
)
13061313
) ++ {
13071314
val sparkProtocExecPath = sys.props.get("spark.protoc.executable.path")

0 commit comments

Comments
 (0)