Title: Generate file descriptor set (.desc) with scalapb
Tags: scalapb
Question: I am using scalapb in a project that needs to have access to the FileDescriptorSet. Is there a way to have scalapb generate the .desc file in addition to all other class files?  Or is there some programatic way of obtaining a FileDescriptorSet from what is already generated?


Here is the accepted answer: Yes, to both questions.

If you are using ```sbt-protoc```, you can have the following definition in your SBT file:

```PB.protocOptions in Compile := Seq(
    "--descriptor_set_out=" + 
        (baseDirectory in Compile).value.getParentFile / "src" / "main" / "resources" /"out.desc"
)
```

One caveat is that you would have to create ```src/main/resources``` yourself, otherwise you would get an error. It would probably be better to generate into ```resourceManaged``` (that would also require creating a directory ahead of time, since ```protoc``` doesn't do that)

You can also build a FileDescriptorSet at run time. For each proto file, ScalaPB generates a Scala object with ```scalaDescriptor``` (and also ```javaDescriptor``` if that's more convenient). The descriptors contains a list of their dependencies which are also ```FileDesciptor```s - you can traverse that tree structure and build a list of ```FileDescriptor```s which is essentially a ```FileDescriptorSet```.

Comment for this answer: In the rare case someone else looks for a way to generate only the `FileDescriptorSet`, `sbt-protoc` happens to provide a generator for that purpose: `Compile / PB.targets += (PB.gens.descriptorSet -> (Compile / crossTarget).value / "my.fds")`


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:10/03/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<scalapb>', 'Title': 'Generate file descriptor set (.desc) with scalapb', 'ViewCount': 423, 'id': 52628371, 'user_AboutMe': None, 'user_AccountId': 5729160.0, 'user_DisplayName': 'James Matlik', 'user_Reputation': 175.0, 'user_Views': 9.0, 'user_id': 4525240.0}}