alexarchambault on 1.6.3
alexarchambault on master
1.6.3 (compare)
lihaoyi on gh-pages
5ad9ae5538f23cab92ccd8c6b1617d8… (compare)
alexarchambault on master
Partly revert 84d48542 (#923) … (compare)
Hey, everyone. In my environment I'm getting a method not found error from protobuf: java.lang.NoSuchMethodError: com.google.protobuf.descriptor.FileDescriptorProto$.parseFrom(
. When I checked the location of the class, it's being loaded from the amm binary. I think it's due to a conflict between an older protobuf library bundled with ammonite and the protobuf that my runtime libraries are depending on.
@ import com.google.protobuf.descriptor.FileDescriptorProto
import com.google.protobuf.descriptor.FileDescriptorProto
@ val klass = classOf[FileDescriptorProto]
klass: Class[FileDescriptorProto] = class com.google.protobuf.descriptor.FileDescriptorProto
@ klass.getResource('/' + klass.getName().replace('.', '/') + ".class")
res5: java.net.URL = jar:file:/usr/local/bin/amm!/com/google/protobuf/descriptor/FileDescriptorProto.class
I think this issue might be related (com-lihaoyi/Ammonite#1177), however when I try the suggested --thin
flag I get errors for missing sun.reflect dependencies java.lang.NoClassDefFoundError: sun/reflect/ConstructorAccessorImpl
mill -i ...
? For example, I've noticed that I need to pass -i
to mill -i main.run
in order for a (cats-effect) readLine
to actually work. Without the -i
it just hangs when it gets to readLine
. I'm wondering if anyone has had the same issue with ammonite?
@lefou ok, thanks. It is odd then that Ammonite seems to have trouble running things like amm Example.sc
where Example.sc
contains:
//Example.sc
import $ivy.`org.typelevel::cats-effect:3.2.5`
import cats.effect.unsafe.implicits._
import cats.effect.IO
val run = for {
_ <- IO.println("Hello")
_ <- IO.println("World")
input <- IO.readLine
_ <- IO.println(s"echo $input")
} yield ()
run.unsafeRunSync()
For me, it only prints "Hello" and then hangs.
amm Example.sc
that does not seem to work properly
cs complete com.lihaoyi:ammonite-interp_2.12.14:
Heya, I'm struggling a bit with multiple ammonite consoles running concurrently, attempting to concurrently modify the fs cache:
java.nio.file.FileAlreadyExistsException: /home/.../.ammonite/rt-11.0.11.jar
at java.base/sun.nio.fs.UnixCopyFile.copy(UnixCopyFile.java:573)
at ...
at io.github.retronym.java9rtexport.Export.rtAt(Export.java:105)
at ammonite.util.Classpath$.classpath(Classpath.scala:76)
at ammonite.compiler.CompilerLifecycleManager.init(CompilerLifecycleManager.scala:92)
at
Is this not supported?
object myplugin extends Plugin {
...
}
context.registerPlugin(myplugin)
@fizzy33 Idk if I get it, but I'm a bit curious, why not use import $file
for this?
Like:MyPlugin.sc
:
object BuildingBlocks extends Plugin {
...
}
val plugin = BuildingBlocks
Then load it like:
import $file.MyPlugin
println(MyPlugin.plugin)
mill
to write a simple app object Main extends IOApp { def run(args: List[Stirng)) = ??? }
in main/src/Main.scala
. Then using mill -i main.run <arg1> <arg2>
. The -i
flag in mill is necessary to make things like IO.readLine
work as expected.
@lihaoyi looking through the mill code is a great help thanks. The last piece that I am missing is where in the code is ammonite running the script and returning the objects in the script. So in mill you have
import mill._, scalalib._
object foo extends ScalaModule {
def scalaVersion = "3.0.2"
}
Something is evaluating the script seeing there is a foo in there and then extracting the instance out. I can see the reflection stuff you have shared as being highly useful and I think I am just missing how I can get the "foo" out of that ammonite script.
val runner: Main =
ammonite.Main(
predefCode = "println(\"running\")",
)
val results = runner.runCode("""object Bob { println("running 2"); def foo = 1 }""")
val results2 = runner.runCode("""println(Bob.toString)""")
cmd0.sc:1: not found: value Bob
val res = println(Bob.toString)
^