Scalapb: Output directory conflicts with IntelliJ

Created on 27 Aug 2015  Â·  13Comments  Â·  Source: scalapb/ScalaPB

When IntelliJ imports an SBT project using the ScalaPB plugin it adds both directories:
_"src_managed / main"_ and _"src_managed / main / compiled_protobuf"_ to it's internal build system.
So when you build the project with IntelliJ the generated classes get included twice, causing conflicts.

is it possible to build directly into the "src_managed / main" directory ?
sbt-protobuf has some instructions about this, but it's not obvious how they map to ScalaPB.

Most helpful comment

@jportway would you mind posting exactly what you did to which build files? I tried adding

scalaSource in PB.protobufConfig <<= (sourceManaged / "main")

to my build.sbt and refreshing the project, but target/src_managed/main isn't showing up as a source folder in the IDEA module.

(It doesn't help that I'm new to SBT, having built all my Scala projects with Gradle till now.)

All 13 comments

Can you try setting "scalaSource in PB.protobufConfig", that should do it.

On Thu, Aug 27, 2015 at 12:37 PM, jportway [email protected] wrote:

When IntelliJ imports an SBT project using the ScalaPB plugin it adds both
directories:
_"src_managed / main"_ and _"src_managed / main / compiled_protobuf"_ to
it's internal build system.
So when you build the project with IntelliJ the generated classes get
included twice, causing conflicts.

is it possible to build directly into the "src_managed / main" directory ?
sbt-protobuf has some instructions
https://github.com/sbt/sbt-protobuf#changing-the-location-of-the-generated-java-files
about this, but it's not obvious how they map to ScalaPB.

—
Reply to this email directly or view it on GitHub
https://github.com/trueaccord/ScalaPB/issues/37.

That worked. Brilliant! Thank you.
Perhaps this is obvious to those who are experienced with SBT but for newcomers like me it would be really useful to have it documented. I've been striuggling all day with verious approaches to the problem.
thanks again.

@jportway would you mind posting exactly what you did to which build files? I tried adding

scalaSource in PB.protobufConfig <<= (sourceManaged / "main")

to my build.sbt and refreshing the project, but target/src_managed/main isn't showing up as a source folder in the IDEA module.

(It doesn't help that I'm new to SBT, having built all my Scala projects with Gradle till now.)

@nadavsr When you said : "Can you try setting "scalaSource in PB.protobufConfig", that should do it.", what do you mean exactly? Setting it with what values?

This is how I configured it to work with InteliJ

PB.protobufSettings
scalaSource in PB.protobufConfig <<= (sourceManaged in Compile)

@dholbrook #126

I tried the same, but for whatever reason in IntelliJ protobufConfig shows in red, as if it's not a member of PB ... any idea(pun not intended) why ?
Thanks!

Are you using sbt-protoc? With it the defaults should just work with IntelliJ.

In plugins.sbt I have

addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.1")

libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin" % "0.5.42"

In build.sbt I have
PB.targets in Compile := Seq(scalapb.gen() -> (sourceManaged in Compile).value)

When I try to add the advised line in build.sbt, the .protobufConfig is red, assume somehow IntelliJ doesn't sees it as a member of PB ... what am I doing wrong ?

In sbt-protoc there's no PB.protobufConfig, this is probably coming from old code. What are you trying to accomplish?

NOTE: in sbt-protoc there's something called PB.ProtobufConfig (with capital P), but it's rarely needed and has a different role (hence the different name)

I'm trying to get visibility of the generated classes in the project. As it is right now, all classes are shown in red, as they're not defined. Compiling via sbt works. But it's a nuisance to not be able to see class members in IntelliJ

Try importing the project to IntelliJ now that you have a few proto files. It looks like if there are no protocol buffers at the time the IntelliJ project is created it will not find the generated sources.

I'll try that, thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mroth picture mroth  Â·  10Comments

jvican picture jvican  Â·  9Comments

danvk picture danvk  Â·  8Comments

jon-morra-zefr picture jon-morra-zefr  Â·  14Comments

ghost picture ghost  Â·  3Comments