0

I am trying to use scalapb to generate case classes from my protobuf. But, I am currently compilation errors.

I have my scalapb.sbt as follows:

addSbtPlugin("com.trueaccord.scalapb" % "sbt-scalapb" % "0.5.26")

libraryDependencies ++= Seq(
  "com.trueaccord.scalapb" %% "compilerplugin" % "0.5.26",
  "com.github.os72" % "protoc-jar" % "3.0.0-b2.1"
)

And, my build.sbt is as follows:

// for scalapb

import com.trueaccord.scalapb.{ScalaPbPlugin => PB}

PB.targets in Compile := Seq(
  scalapb.gen() -> (sourceManaged in Compile).value
)

PB.protobufSettings

PB.runProtoc in PB.protobufConfig := (args =>
  com.github.os72.protocjar.Protoc.runProtoc("-v241" +: args.toArray))

libraryDependencies ++= Seq(
    "io.grpc" % "grpc-netty" % "0.14.0",
    "com.trueaccord.scalapb" %% "scalapb-runtime-grpc" % (PB.scalapbVersion in PB.protobufConfig).value
)

Also, I have created a sample .proto file src\main\protobuf as follows:

syntax = "proto2"

package org.pk.stream.protos

message Tweet {
    required string filter_level = 1;
}

Now, when I am trying to sbt compile, I am getting the following error:

S:\MyRepos\LogStreaming>sbt compile
[info] Loading global plugins from C:\Users\pkumar25\.sbt\0.13\plugins
[info] Loading project definition from S:\MyRepos\RLoggerStreaming\project
S:\MyRepos\LogStreaming\build.sbt:21: error: object trueaccord is not a 
member of package com
import com.trueaccord.scalapb.{ScalaPbPlugin => PB}
           ^
sbt.compiler.EvalException: Type error in expression
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q

Could someone help me in resolving this error?

I am also little confused between the scalapb versions, com.thesamet.scalapb (https://scalapb.github.io/sbt-settings.html) and com.trueaccord.scalapb (https://mvnrepository.com/artifact/com.trueaccord.scalapb). I am curious, which one should be used and how to use that aptly?

Much appreciated!

PankajK
  • 187
  • 3
  • 14

2 Answers2

0

Author of ScalaPB here. About two years ago ScalaPB has transitioned to be developed outside TrueAccord, and as a result we followed by changing artifact and package names accordingly.

You are referencing in your question a very old version (0.5.26) that has been released prior to this transition. I would recommend using the latest one (0.8.x) by following the instructions in our documentation. If you hit any issues don't hesitate to ask here or on our Gitter channel.

thesamet
  • 6,382
  • 2
  • 31
  • 42
  • Thanks @thesamet! I have updated my `scalapb.sbt` and `build.sbt` as per your suggestion. However, I am getting this error during `sbt compile`: [info] Resolving com.thesamet#sbt-protoc;0.99.15 ... [error] Server access Error: Remote host closed connection during handshake url=https://repo.typesafe.com/typesafe/ivy-releases/com.thesamet/sbt-protoc/scala_2.10/sbt_0.13/0.99.15/ivys/ivy.x ml [error] Server access Error: Remote host closed connection during handshake url=https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.thesamet/sbt-protoc/scala_2.10/sbt_0.13/0.99.15/iv ys/ivy.xml – PankajK Jan 08 '19 at 22:57
  • I've seen `repo.typesafe.com` timing out earlier today myself and have heard other users complaining on this. It looks like an intermittent issue with that repo that is unrelated to ScalaPB, so please try again. Also, make sure you are on a recent version of SBT. Create a `project/build.properties` the following line: `sbt.version=1.2.8` – thesamet Jan 09 '19 at 02:52
  • @thesamet The documentation linked does not mention the `import` statement. it that a fixable oversight? Are there any working examples of projects that use ScalePB? – Jesse Chisholm Sep 11 '19 at 21:23
  • Hi @JesseChisholm, I don't believe that the documentation misses any `import` statement, or at least I'm not sure I understand what you are referring to. If you are experiencing any problem with getting ScalaPB working in your project, can you post a new question with a description of what you are trying to do and what error you are seeing? Feel free also to reach out through our mailing list or gitter – thesamet Sep 12 '19 at 00:56
-1

Per https://scalapb.github.io/migrating.html

From version 0.7.0 and onwards, ScalaPB artifacts are published under the com.thesamet.scalapb group id instead of the com.trueaccord.scalapb group id.

In addition, all classes in the com.trueaccord.scalapb are moved to the scalapb top-level package. During 0.7.x, we will keep type aliases and references in the original com.trueaccord.scalapb location so you may get deprecation warnings, but your code is unlikely to break.

Moreover, it looks like the author wants you to use the sbt-protoc plugin.

However if you find it necessary to use sbt-scalapb, I think the fix is to just enable the plugin in your build.sbt:

enablePlugin(ScalaPbPlugin)

The ScalaPbPlugin source shows that it isn't an auto-plugin, so it will require manual enabling.

Community
  • 1
  • 1
Mark Kegel
  • 4,476
  • 3
  • 21
  • 21