spotify / scio

A Scala API for Apache Beam and Google Cloud Dataflow.
https://spotify.github.io/scio
Apache License 2.0
2.56k stars 513 forks source link

cannot launch repl from sbt if using scio-jdbc #1324

Closed iamneal closed 6 years ago

iamneal commented 6 years ago

My code compiles and runs, but when I try and start up the repl from sbt I get this error

sbt -Dscala.color -mem 3600
[info] Loading settings from idea.sbt ...
[info] Loading global plugins from /Users/<user>/.sbt/1.0/plugins
[info] Loading settings from plugins.sbt,protoc.sbt ...
[info] Loading project definition from /Users/<user>/scio-job/project
[info] Loading settings from build.sbt ...
[info] Set current project to scio-job (in build file:/Users/<user>/scio-job/)
[info] sbt server started at local:///Users/<user>/.sbt/1.0/server/89f8de8a5fe3e4ed4630/sock
sbt:scio-job> repl/run
[info] Packaging /Users/<user>/scio-job/target/scala-2.11/scio-job_2.11-0.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[info] Running com.spotify.scio.repl.ScioShell 
Welcome to
                 _____
    ________________(_)_____
    __  ___/  ___/_  /_  __ \
    _(__  )/ /__ _  / / /_/ /
    /____/ \___/ /_/  \____/   version 0.5.7

Using Scala version 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 9.0.4)

Type in expressions to have them evaluated.
Type :help for more information.

[run-main-0] INFO org.apache.beam.sdk.extensions.gcp.options.GcpOptions$DefaultProjectFactory - Inferred default GCP project '<removed>' from gcloud. If this is the incorrect project, please cancel this Pipeline and specify the command-line argument --project.
Using 'tcn-cloud-dev' as your BigQuery project.
BigQuery client available as 'bq'
java.lang.SecurityException: Prohibited package name: java.sql
  at java.base/java.lang.ClassLoader.preDefineClass(ClassLoader.java:889)
  at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1005)
  at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
  at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:545)
  at java.base/java.net.URLClassLoader.access$100(URLClassLoader.java:83)
  at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:453)
  at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:447)
  at java.base/java.security.AccessController.doPrivileged(Native Method)
  at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:446)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:563)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
  at com.spotify.scio.repl.ScioReplClassLoader.loadClass(ScioReplClassLoader.scala:69)
  at com.fasterxml.jackson.databind.ser.std.StdJdkSerializers.all(StdJdkSerializers.java:55)
  at com.fasterxml.jackson.databind.ser.BasicSerializerFactory.<clinit>(BasicSerializerFactory.java:93)
  at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:581)
  at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:480)
  at org.apache.beam.sdk.options.PipelineOptionsFactory.<clinit>(PipelineOptionsFactory.java:466)
  ... 63 elided
Scio context available as 'sc'
<console>:25: error: not found: value sc
       val _ioCommands = new com.spotify.scio.repl.IoCommands(sc.options)
                                                              ^

scio> Interpreter encountered errors during initialization!

Exception: sbt.TrapExitSecurityException thrown from the UncaughtExceptionHandler in thread "run-main-0"

The problem started showing up after I included the scio-jdbc package

Here is my build.sbt

import sbt._
import Keys._

val scioVersion = "0.5.7"
val beamVersion = "2.5.0"
val scalaMacrosVersion = "2.1.1"

lazy val commonSettings = Defaults.coreDefaultSettings ++ Seq(
  organization          := "example",
  // Semantic versioning http://semver.org/
  version               := "0.1.0-SNAPSHOT",
  scalaVersion          := "2.11.12",
  scalacOptions         ++= Seq("-target:jvm-1.8",
                                "-deprecation",
                                "-feature",
                                "-unchecked"),
  javacOptions          ++= Seq("-source", "1.8",
                                "-target", "1.8")
)

lazy val paradiseDependency =
  "org.scalamacros" % "paradise" % scalaMacrosVersion cross CrossVersion.full
lazy val macroSettings = Seq(
  libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,
  addCompilerPlugin(paradiseDependency)
)

lazy val noPublishSettings = Seq(
  publish := {},
  publishLocal := {},
  publishArtifact := false
)

lazy val root: Project = Project(
  "scio-job",
  file(".")
).settings(
  commonSettings ++ macroSettings ++ noPublishSettings,
  description := "scio job",
  libraryDependencies ++= Seq(
    "com.spotify" %% "scio-core" % scioVersion,
    "com.spotify" %% "scio-test" % scioVersion % "test",
    "com.spotify" %% "scio-jdbc" % scioVersion,
    "org.apache.beam" % "beam-runners-direct-java" % beamVersion,
    // optional dataflow runner
    "org.apache.beam" % "beam-runners-google-cloud-dataflow-java" % beamVersion,
    "org.slf4j" % "slf4j-simple" % "1.7.25",
    "org.json" % "json" % "20180813",
    "io.grpc" % "grpc-netty" % scalapb.compiler.Version.grpcJavaVersion,
    "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
    "org.postgresql" % "postgresql" % "42.2.4",
    "com.google.cloud.sql" % "postgres-socket-factory" % "1.0.10"
    // "com.google.cloud" % "google-cloud-pubsub" % "1.36.0",
    // "com.google.cloud" % "google-cloud-storage" % "1.36.0"
  ),
  mainClass in Compile := Some("example.P3Extractor")
).enablePlugins(PackPlugin)

lazy val repl: Project = Project(
  "repl",
  file(".repl")
).settings(
  commonSettings ++ macroSettings ++ noPublishSettings,
  description := "Scio REPL for scio job",
  libraryDependencies ++= Seq(
    "com.spotify" %% "scio-repl" % scioVersion
  ),
  mainClass in Compile := Some("com.spotify.scio.repl.ScioShell")
).dependsOn(
  root
)
// SCALAPB STUFF
PB.targets in Compile := Seq(
  PB.gens.java -> (sourceManaged in Compile).value,
  scalapb.gen() -> (sourceManaged in Compile).value
)
nevillelyh commented 6 years ago
val scioVersion = "0.5.7"
val beamVersion = "2.5.0"

Scio 0.5.7 depends on Beam 2.6.0, although I'm not sure this is the root cause.

@syodage take a look when you get a chance?

iamneal commented 6 years ago

@nevillelyh Thanks for catching that. I will fix that and try again. Though like you, I'm not expecting that to be the root cause.

EDIT: I updated the beam version to 2.6.0 in my build sbt and rebuilt and tried the repl. Unfortunately it is the same error

syodage commented 6 years ago

@iamneal seems like java 9 class loader problem, Using Scala version 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 9.0.4) I don't think scio is ready to use with Java 9 yet(@nevillelyh correct me if i am wrong) try with Java 8 and see.

from Java 9

The extension class loader has been renamed; it is now the platform class loader. All classes in the Java SE Platform are guaranteed to be visible through the platform class loader. In addition, the classes in modules that are standardized under the Java Community Process but not part of the Java SE Platform are guaranteed to be visible through the platform class loader.

Just because a class is visible through the platform class loader does not mean the class is actually defined by the platform class loader. Some classes in the Java SE Platform are defined by the platform class loader while others are defined by the bootstrap class loader. Applications should not depend on which class loader defines which platform class.

The changes in JDK 9 may impact code that creates class loaders with null (that is, the bootstrap class loader) as the parent class loader and assumes that all platform classes are visible to the parent. Such code may need to be changed to use the platform class loader as the parent (see ClassLoader.getPlatformClassLoader).

but scio repl class load logic not comply with that https://github.com/spotify/scio/blob/master/scio-repl/src/main/scala/com/spotify/scio/repl/ScioReplClassLoader.scala#L48

nevillelyh commented 6 years ago

@iamneal can you verify that this works with Java 8? Gonna close this for now if that's the case.

iamneal commented 6 years ago

yeah that was the problem, thanks for your help