@@ -15,6 +15,7 @@ object NoProcessLogger extends ProcessLogger {
1515final case class ProtosProject (
1616 module : ModuleID ,
1717 grpc : Boolean ,
18+ protoPackage : String ,
1819 buildNumber : Int = 0 ,
1920 packageName : Option [String ] = None ,
2021 dependencies : Seq [ProtosProject ] = Seq .empty
@@ -27,6 +28,8 @@ final case class ProtosProject(
2728
2829 val projectName = module.name + scalapbMajorMinor.replace('.' , '_' )
2930
31+ val optionsFile = protoPackage.replace('.' , '/' ) + " /scalapb-options.proto"
32+
3033 sbt
3134 .Project (projectName, new File (projectName))
3235 .settings(
@@ -67,7 +70,38 @@ final case class ProtosProject(
6770 publish / skip := (sys.env
6871 .getOrElse(" PUBLISH_ONLY" , basePackageName) != basePackageName),
6972 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+ }
71105 )
72106 }
73107
@@ -77,7 +111,7 @@ final case class ProtosProject(
77111 )
78112
79113 val scalapb10 : Project =
80- protoProject(" 0.10.10 " ).dependsOn(
114+ protoProject(" 0.10.11 " ).dependsOn(
81115 dependencies.map(d => ClasspathDependency (d.scalapb10, None )): _*
82116 )
83117
0 commit comments