@@ -15,6 +15,7 @@ object NoProcessLogger extends ProcessLogger {
15
15
final case class ProtosProject (
16
16
module : ModuleID ,
17
17
grpc : Boolean ,
18
+ protoPackage : String ,
18
19
buildNumber : Int = 0 ,
19
20
packageName : Option [String ] = None ,
20
21
dependencies : Seq [ProtosProject ] = Seq .empty
@@ -27,6 +28,8 @@ final case class ProtosProject(
27
28
28
29
val projectName = module.name + scalapbMajorMinor.replace('.' , '_' )
29
30
31
+ val optionsFile = protoPackage.replace('.' , '/' ) + " /scalapb-options.proto"
32
+
30
33
sbt
31
34
.Project (projectName, new File (projectName))
32
35
.settings(
@@ -67,7 +70,38 @@ final case class ProtosProject(
67
70
publish / skip := (sys.env
68
71
.getOrElse(" PUBLISH_ONLY" , basePackageName) != basePackageName),
69
72
sonatypeBundleDirectory := (ThisBuild / baseDirectory).value / " target" / " sonatype-staging" ,
70
- publishArtifact in (Compile , packageDoc) := scalaVersion.value != Scala3
73
+ publishArtifact in (Compile , packageDoc) := scalaVersion.value != Scala3 ,
74
+ Compile / resourceGenerators += Def .task {
75
+
76
+ val packageOptionsFile =
77
+ (Compile / resourceManaged).value / optionsFile
78
+ IO .write(
79
+ packageOptionsFile,
80
+ s """ |// This file is generated by ScalaPB/common-protos project/BuildHelpers.scala.
81
+ |// It is added as an input in user's builds to ensure the protos shipped with
82
+ |// this jar are interpreted with the original generator options, and not influenced
83
+ |// by generator options in the user's build.
84
+ |
85
+ |syntax = "proto3";
86
+ |package $protoPackage;
87
+ |
88
+ |import "scalapb/scalapb.proto";
89
+ |option (scalapb.options) = {
90
+ | scope: PACKAGE
91
+ | flat_package: false
92
+ | lenses: true
93
+ | // java_conversions as a file-level option is only introduced in 0.10.11
94
+ | // so it is not yet included here for backwards-compatiblity.
95
+ | // java_conversions: true
96
+ | preserve_unknown_fields: true
97
+ |};
98
+ """ .stripMargin
99
+ )
100
+ Seq (packageOptionsFile)
101
+ }.taskValue,
102
+ Compile / packageBin / packageOptions += {
103
+ Package .ManifestAttributes (" ScalaPB-Options-Proto" -> optionsFile)
104
+ }
71
105
)
72
106
}
73
107
@@ -77,7 +111,7 @@ final case class ProtosProject(
77
111
)
78
112
79
113
val scalapb10 : Project =
80
- protoProject(" 0.10.10 " ).dependsOn(
114
+ protoProject(" 0.10.11 " ).dependsOn(
81
115
dependencies.map(d => ClasspathDependency (d.scalapb10, None )): _*
82
116
)
83
117
0 commit comments