Skip to content

Commit 174b62d

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]>
1 parent df720c1 commit 174b62d

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
@@ -648,8 +648,10 @@ object Core {
648648
"com.google.protobuf" % "protobuf-java" % protoVersion % "protobuf"
649649
)
650650
},
651+
// Use Maven's output directory so sbt and Maven can share generated sources.
652+
// Core uses protoc-jar-maven-plugin which outputs to target/generated-sources.
651653
(Compile / PB.targets) := Seq(
652-
PB.gens.java -> (Compile / sourceManaged).value
654+
PB.gens.java -> target.value / "generated-sources"
653655
)
654656
) ++ {
655657
val sparkProtocExecPath = sys.props.get("spark.protoc.executable.path")
@@ -734,19 +736,20 @@ object SparkConnectCommon {
734736
) ++ {
735737
val sparkProtocExecPath = sys.props.get("spark.protoc.executable.path")
736738
val connectPluginExecPath = sys.props.get("connect.plugin.executable.path")
739+
// Use Maven's output directory so sbt and Maven can share generated sources
737740
if (sparkProtocExecPath.isDefined && connectPluginExecPath.isDefined) {
738741
Seq(
739742
(Compile / PB.targets) := Seq(
740-
PB.gens.java -> (Compile / sourceManaged).value,
741-
PB.gens.plugin(name = "grpc-java", path = connectPluginExecPath.get) -> (Compile / sourceManaged).value
743+
PB.gens.java -> target.value / "generated-sources" / "protobuf" / "java",
744+
PB.gens.plugin(name = "grpc-java", path = connectPluginExecPath.get) -> target.value / "generated-sources" / "protobuf" / "grpc-java"
742745
),
743746
PB.protocExecutable := file(sparkProtocExecPath.get)
744747
)
745748
} else {
746749
Seq(
747750
(Compile / PB.targets) := Seq(
748-
PB.gens.java -> (Compile / sourceManaged).value,
749-
PB.gens.plugin("grpc-java") -> (Compile / sourceManaged).value
751+
PB.gens.java -> target.value / "generated-sources" / "protobuf" / "java",
752+
PB.gens.plugin("grpc-java") -> target.value / "generated-sources" / "protobuf" / "grpc-java"
750753
)
751754
)
752755
}
@@ -1286,7 +1289,9 @@ object SqlApi {
12861289
(Antlr4 / antlr4PackageName) := Some("org.apache.spark.sql.catalyst.parser"),
12871290
(Antlr4 / antlr4GenListener) := true,
12881291
(Antlr4 / antlr4GenVisitor) := true,
1289-
(Antlr4 / antlr4TreatWarningsAsErrors) := true
1292+
(Antlr4 / antlr4TreatWarningsAsErrors) := true,
1293+
// Use Maven's output directory so sbt and Maven can share generated sources
1294+
(Antlr4 / javaSource) := target.value / "generated-sources" / "antlr4"
12901295
)
12911296
}
12921297

@@ -1303,8 +1308,10 @@ object SQL {
13031308
"com.google.protobuf" % "protobuf-java" % protoVersion % "protobuf"
13041309
)
13051310
},
1311+
// Use Maven's output directory so sbt and Maven can share generated sources.
1312+
// sql/core uses protoc-jar-maven-plugin which outputs to target/generated-sources.
13061313
(Compile / PB.targets) := Seq(
1307-
PB.gens.java -> (Compile / sourceManaged).value
1314+
PB.gens.java -> target.value / "generated-sources"
13081315
)
13091316
) ++ {
13101317
val sparkProtocExecPath = sys.props.get("spark.protoc.executable.path")

0 commit comments

Comments
 (0)