PankajK
PankajK

Reputation: 307

Issue while sbt compile with scalapb

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!

Upvotes: 0

Views: 2075

Answers (2)

Mark Kegel
Mark Kegel

Reputation: 4520

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.

Upvotes: 0

thesamet
thesamet

Reputation: 6582

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.

Upvotes: 1

Related Questions