Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not compile scrooge generated code #254

Open
QuantumBear opened this issue Dec 13, 2016 · 9 comments
Open

Can not compile scrooge generated code #254

QuantumBear opened this issue Dec 13, 2016 · 9 comments
Assignees

Comments

@QuantumBear
Copy link

QuantumBear commented Dec 13, 2016

I try to use scrooge to compile thrift files to Scala files, but get lots of compile errors even I use the code in demos/scrooge-maven-demo.

Expected behavior

Build success with mvn clean install command.

Actual behavior

Get lots of compile erros

Here is error log when I compile scrooge-maven-demo.

[ERROR] /home/sili/code/scrooge/demos/scrooge-maven-demo/target/generated-sources/thrift/scrooge/com/twitter/mydemo/renamed/UserService.scala:9: error: object HasThriftStructCodec3 is not a member of package com.twitter.scrooge
[ERROR] import com.twitter.scrooge.{
[ERROR] ^
[ERROR] /home/sili/code/scrooge/demos/scrooge-maven-demo/target/generated-sources/thrift/scrooge/com/twitter/mydemo/renamed/User.scala:9: error: object HasThriftStructCodec3 is not a member of package com.twitter.scrooge
[ERROR] import com.twitter.scrooge.{
[ERROR] ^
[ERROR] /home/sili/code/scrooge/demos/scrooge-maven-demo/target/generated-sources/thrift/scrooge/com/twitter/mydemo/renamed/User.scala:353: error: not found: type HasThriftStructCodec3
[ERROR] with HasThriftStructCodec3[User]
[ERROR] ^
[ERROR] /home/sili/code/scrooge/demos/scrooge-maven-demo/src/main/scala/com/twitter/example/Demo.scala:37: error: overloaded method value stack with alternatives:
[ERROR] [Req1, Rep1](server: com.twitter.finagle.server.StackBasedServer[Req1,Rep1])com.twitter.finagle.builder.ServerBuilder[Req1,Rep1,com.twitter.finagle.builder.ServerConfig.Yes,Nothing,Nothing]
[ERROR] [Req1, Rep1](mk: com.twitter.finagle.Stack.Params => com.twitter.finagle.Server[Req1,Rep1])com.twitter.finagle.builder.ServerBuilder[Req1,Rep1,com.twitter.finagle.builder.ServerConfig.Yes,Nothing,Nothing]

And here is the error log when compile my project.

[ERROR] /home/sili/workspace/new-sessionlog-proto/target/generated-sources/thrift/scrooge/com/mediav/data/log/unitedlog/ShowInfo.scala:9: object HasThriftStructCodec3 is not a member of package com.twitter.scrooge
[ERROR] import com.twitter.scrooge.{
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/target/generated-sources/thrift/scrooge/com/mediav/data/log/unitedlog/ShowInfo.scala:3045: not found: type HasThriftStructCodec3
[ERROR] with HasThriftStructCodec3[ShowInfo]
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/src/main/scala/com/mvad/sessionlog/newSessionlog.scala:32: value isSetFraudInfo is not a member of com.mediav.data.log.unitedlog.ShowInfo
[ERROR] if (showInfo.isSetFraudInfo
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/target/generated-sources/thrift/scrooge/com/mediav/data/log/unitedlog/FraudInfo.scala:9: object HasThriftStructCodec3 is not a member of package com.twitter.scrooge
[ERROR] import com.twitter.scrooge.{
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/target/generated-sources/thrift/scrooge/com/mediav/data/log/unitedlog/FraudInfo.scala:569: not found: type HasThriftStructCodec3
[ERROR] with HasThriftStructCodec3[FraudInfo]
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/src/main/scala/com/mvad/sessionlog/newSessionlog.scala:34: value fraudReasons is not a member of Option[com.mediav.data.log.unitedlog.FraudInfo]
[ERROR] showInfo.fraudInfo.fraudReasons.mkString(",")
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/target/generated-sources/thrift/scrooge/com/mediav/data/log/unitedlog/UnitedEvent.scala:9: object HasThriftStructCodec3 is not a member of package com.twitter.scrooge
[ERROR] import com.twitter.scrooge.{
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/target/generated-sources/thrift/scrooge/com/mediav/data/log/unitedlog/UnitedEvent.scala:1096: not found: type HasThriftStructCodec3
[ERROR] with HasThriftStructCodec3[UnitedEvent]
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/src/main/scala/com/mvad/sessionlog/newSessionlog.scala:44: trait UnitedEvent is abstract; cannot be instantiated
[ERROR] Try(ThriftUtils.detectAndDeserialize(ueBytes, new UnitedEvent())) match {
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/src/main/scala/com/mvad/sessionlog/newSessionlog.scala:45: too many arguments for method apply: (x: A)Some[A] in object Some
[ERROR] case Success(ue) => Some(ue.getEventType.type,ue)
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/target/generated-sources/thrift/scrooge/com/mediav/data/log/unitedlog/AdSlotClickInfo.scala:9: object HasThriftStructCodec3 is not a member of package com.twitter.scrooge
[ERROR] import com.twitter.scrooge.{
[ERROR] ^
[ERROR] /home/sili/workspace/new-sessionlog-proto/target/generated-sources/thrift/scrooge/com/mediav/data/log/unitedlog/AdSlotClickInfo.scala:363: not found: type HasThriftStructCodec3
[ERROR] with HasThriftStructCodec3[AdSlotClickInfo]
[ERROR] ^

Steps to reproduce the behavior

Add this configuration to my pom.xml then run mvn clean install

<dependency>
  <groupId>com.twitter</groupId>
  <artifactId>scrooge-core_${scala.binary.version}</artifactId>
  <version>4.6.0</version>
  <exclusions>
    <exclusion>
      <groupId>org.apache.thrift</groupId>
      <artifactId>libthrift</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Add this plugin configuration.

 <plugin>
    <groupId>com.twitter</groupId>
    <artifactId>scrooge-maven-plugin</artifactId>
    <version>4.12.0</version>
    <configuration>
      <thriftNamespaceMappings>
        <thriftNamespaceMapping>
          <from>com.mediav.data.log.unitedlog</from>
          <to>com.mediav.data.log.unitedlog</to>
        </thriftNamespaceMapping>
      </thriftNamespaceMappings>
      <language>scala</language>
      <buildExtractedThrift>false</buildExtractedThrift>
    </configuration>
    <executions>
      <execution>
        <id>thrift-sources</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>compile</goal>
        </goals>
      </execution>
      <execution>
        <id>thrift-test-sources</id>
        <phase>generate-test-sources</phase>
        <goals>
          <goal>testCompile</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
@filipesabella
Copy link

@QuantumBear having the same problem here, did you find a solution?

@nepthar
Copy link
Contributor

nepthar commented May 4, 2017

Looks like this issue is from using a rather outdated version of scrooge. Try using the same version of scrooge-core as you're using with the plugin.

@QuantumBear
Copy link
Author

run command 'mvn clean install' with latest trunk code.

[ERROR] /home/sili/code/scrooge/demos/scrooge-maven-demo/src/main/scala/com/twitter/example/Demo.scala:14: error: overloaded method value hosts with alternatives:
[ERROR] (address: java.net.InetSocketAddress)com.twitter.finagle.builder.ClientBuilder[Nothing,Nothing,com.twitter.finagle.builder.ClientConfig.Yes,Nothing,Nothing]
[ERROR] (sockaddrs: Seq[java.net.InetSocketAddress])com.twitter.finagle.builder.ClientBuilder[Nothing,Nothing,com.twitter.finagle.builder.ClientConfig.Yes,Nothing,Nothing]
[ERROR] (hostnamePortCombinations: String)com.twitter.finagle.builder.ClientBuilder[Nothing,Nothing,com.twitter.finagle.builder.ClientConfig.Yes,Nothing,Nothing]
[ERROR] cannot be applied to (Seq[java.net.SocketAddress])
[ERROR] .hosts(Seq(address))
[ERROR] ^
[ERROR] /home/sili/code/scrooge/demos/scrooge-maven-demo/src/main/scala/com/twitter/example/Demo.scala:37: error: overloaded method value stack with alternatives:
[ERROR] [Req1, Rep1](server: com.twitter.finagle.server.StackBasedServer[Req1,Rep1])com.twitter.finagle.builder.ServerBuilder[Req1,Rep1,com.twitter.finagle.builder.ServerConfig.Yes,Nothing,
Nothing]
[ERROR] [Req1, Rep1](mk: com.twitter.finagle.Stack.Params => com.twitter.finagle.Server[Req1,Rep1])com.twitter.finagle.builder.ServerBuilder[Req1,Rep1,com.twitter.finagle.builder.ServerConf
ig.Yes,Nothing,Nothing]
[ERROR] cannot be applied to (com.twitter.finagle.Thrift.Client)
[ERROR] .stack(Thrift.client)
[ERROR] ^
[ERROR] /home/sili/code/scrooge/demos/scrooge-maven-demo/target/generated-sources/thrift/scrooge/com/twitter/mydemo/renamed/UserService.scala:60: error: type Filterable is not a member of obj
ect com.twitter.finagle.thrift.ThriftServiceIface
[ERROR] with com.twitter.finagle.thrift.ThriftServiceIface.Filterable[ServiceIface] {
[ERROR] ^
[ERROR] /home/sili/code/scrooge/demos/scrooge-maven-demo/target/generated-sources/thrift/scrooge/com/twitter/mydemo/renamed/UserService.scala:80: error: type mismatch;
[ERROR] found : com.twitter.finagle.Service[com.twitter.mydemo.renamed.UserService.CreateUser.Args,com.twitter.mydemo.renamed.UserService.CreateUser.Result]
[ERROR] required: com.twitter.finagle.Service[com.twitter.mydemo.renamed.UserService.CreateUser.Args,com.twitter.mydemo.renamed.UserService.CreateUser.SuccessType]
[ERROR] (which expands to) com.twitter.finagle.Service[com.twitter.mydemo.renamed.UserService.CreateUser.Args,com.twitter.mydemo.renamed.User]
[ERROR] createUser = ThriftServiceIface(self.CreateUser, binaryService, pf, stats)
[ERROR] ^
[ERROR] /home/sili/code/scrooge/demos/scrooge-maven-demo/target/generated-sources/thrift/scrooge/org/apache/scribe/thriftscala/Scribe.scala:60: error: type Filterable is not a member of objec
t com.twitter.finagle.thrift.ThriftServiceIface
[ERROR] with com.twitter.finagle.thrift.ThriftServiceIface.Filterable[ServiceIface] {
[ERROR] ^
[ERROR] /home/sili/code/scrooge/demos/scrooge-maven-demo/target/generated-sources/thrift/scrooge/org/apache/scribe/thriftscala/Scribe.scala:80: error: type mismatch;
[ERROR] found : com.twitter.finagle.Service[org.apache.scribe.thriftscala.Scribe.Log.Args,org.apache.scribe.thriftscala.Scribe.Log.Result]
[ERROR] required: com.twitter.finagle.Service[org.apache.scribe.thriftscala.Scribe.Log.Args,org.apache.scribe.thriftscala.Scribe.Log.SuccessType]
[ERROR] (which expands to) com.twitter.finagle.Service[org.apache.scribe.thriftscala.Scribe.Log.Args,org.apache.scribe.thriftscala.ResultCode]
[ERROR] log = ThriftServiceIface(self.Log, binaryService, pf, stats)
[ERROR] ^
[ERROR] 6 errors found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 08:06 min
[INFO] Finished at: 2017-05-05T17:39:19+08:00
[INFO] Final Memory: 16M/292M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.1.0:compile (default) on project scrooge-demo: wrap: org.apache.commons.exec.ExecuteException: Process exited with an er
ror: 1(Exit value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@kevinoliver
Copy link
Contributor

@QuantumBear yeah that looks like a bug.

and worse, it looks like we have nothing in the way of tests (or even compilation!) for the demos.

it probably wouldn't be too hard to fix based on a quick look around in that folder.

@mosesn
Copy link
Contributor

mosesn commented May 9, 2017

@QuantumBear I'm going to take a stab at this. In the long run, we should have a travisci job which will fail if the demos don't build. Would you be interested in making a PR for that?

@mosesn mosesn self-assigned this May 9, 2017
finaglehelper pushed a commit that referenced this issue May 9, 2017
Problem

The maven demos are broken, cf #254

Solution

Fix 'em and update the libraries and plugin.

RB_ID=916328
@gregsilin
Copy link

I just ran into the same issue on Scrooge 18.5.0 with libthrift 0.10.0, which is the default version included with that version of Scrooge. I played around with different versions of libthrift, but no dice.

Are there any workarounds for the issue?

@mosesn
Copy link
Contributor

mosesn commented Jun 18, 2018

@gregsilin sorry for not getting back to you for a while. just to confirm, the issue you're seeing is with the scrooge demos?

@mmlac
Copy link

mmlac commented Jan 18, 2019

I ran into that just now when the maven (or sbt in my case) and the lib versions aren't aligned. Especially recently moving things from .scrooge to .finagle.thrift threw me off because I updated the lib but not the plugin:

object ThriftService is not a member of package com.twitter.scrooge

I don't know if this is the exact same as the — now quite old — original issue, but it seems something to verify, as generator & code versions not matching produce these weird "class no found" errors.

@tavoaqp-zz
Copy link

I had the same problem and solved it by updating the sbt-scrooge-plugin in project/plugins.sbt like so:

addSbtPlugin("com.twitter" %% "scrooge-sbt-plugin" % "19.1.0")

and adding these dependencies in build.sbt:

"com.github.finagle" %% "finch-core" % "0.27.0",
"com.twitter" %% "finagle-thrift" % "19.1.0",
"com.twitter" %% "util-core" % "19.1.0",
"com.twitter" %% "scrooge-core" % "19.1.0"

As you can see I'm using Finagle. Hope it helps.

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

No branches or pull requests

8 participants