Skip to content

Conversation

arminsumo
Copy link

@arminsumo arminsumo commented Sep 6, 2025

Extend the scalapb plugin to allow for generating scala, or java, or both.
Can probably be extended in the future to support arbitrary generators https://scalapb.github.io/docs/scalapbc/#loading-additional-generators-from-maven

@arminsumo arminsumo force-pushed the scalapb-support-java-generation branch from 5e06bff to 4e8e912 Compare September 6, 2025 16:13

object TutorialWithScalaAndJavaGen extends TutorialBase {
object core extends TutorialModule {
override def scalaPBGenerators = Seq[Generator](ScalaGen, JavaGen)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we need to explicitly define the type of the Seq here, otherwise upickle can't find the implicit reader.
although having a single value in there seems to work fine...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does making Generator an enum fixes the issue?

@arminsumo arminsumo marked this pull request as ready for review September 6, 2025 17:22
@lihaoyi lihaoyi requested a review from lefou September 10, 2025 01:28
@lihaoyi
Copy link
Member

lihaoyi commented Sep 10, 2025

@lefou could you help review this one? Thanks!

Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. This addition look good. I added some comments below.

Can you also update the plugin readme.adoc which gets rendered as part of the documentation?

Comment on lines +116 to +129
sealed trait Generator derives ReadWriter {
def generator: String
def supportsScalaPBOptions: Boolean
}
case object ScalaGen extends Generator {
override def generator: String = "--scala_out"
override def supportsScalaPBOptions: Boolean = true
}
case object JavaGen extends Generator {
override def generator: String = "--java_out"
override def supportsScalaPBOptions: Boolean =
false // Java options are specified directly in the proto file
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this could be an enum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you define Generator in it's own file? It also needs some docs what supportsScalaPBOptions means. I'd prefer to name it supportsScalaPbOptions (small b).

Are there other generators we could support? Can we add an CustomGen to let the user define and use other generators?


def scalaPBVersion: T[String]

def scalaPBGenerators: T[Seq[Generator]] = Seq[Generator](ScalaGen)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have some docs here which answers: What is a generator? Which can be choosen from? What is the default?


object TutorialWithScalaAndJavaGen extends TutorialBase {
object core extends TutorialModule {
override def scalaPBGenerators = Seq[Generator](ScalaGen, JavaGen)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does making Generator an enum fixes the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants