Marin
Marin

Reputation: 931

How to package an akka project for a netlogo extension?

I am trying to make a simple NetLogo extension that is based on akka. However, whenever I try to load the extension in NetLogo, I get the error:

Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'

Which obviously means that some configuration is missing. I then proceded to add reference.conf to my resources folder but with no luck.

The last thing I tried was to use the sbt-assemblty plugin, but I keep getting the same error. So this is my build.sbt:

name := "TestAkka"

version := "1.0"

scalaVersion := "2.11.7"

scalaSource in Compile <<= baseDirectory(_ / "src")

scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xfatal-warnings",
    "-encoding", "us-ascii")

libraryDependencies ++= Seq(
    "org.nlogo" % "NetLogo" % "5.3.0" from
      "http://ccl.northwestern.edu/devel/NetLogo-5.3-17964bb.jar",
    "asm" % "asm-all" % "3.3.1",
    "org.picocontainer" % "picocontainer" % "2.13.6",
    "com.typesafe" % "config" % "1.3.0",
    "com.typesafe.akka" %% "akka-actor" % "2.4.1",
    "com.typesafe.akka" %% "akka-remote" % "2.4.1"
)

artifactName := { (_, _, _) => "sample-scala.jar" }

packageOptions := Seq(
    Package.ManifestAttributes(
        ("Extension-Name", "sample-scala"),
        ("Class-Manager", "main.scala.akkatest.TestClassManager"),
        ("NetLogo-Extension-API-Version", "5.3")))


packageBin in Compile <<= (packageBin in Compile, baseDirectory, streams) map {
    (jar, base, s) =>

        IO.copyFile(jar, base / "sample-scala.jar")

        Process("pack200 --modification-time=latest --effort=9 --strip-debug " +
          "--no-keep-file-order --unknown-attribute=strip " +
          "sample-scala.jar.pack.gz sample-scala.jar").!!
        if(Process("git diff --quiet --exit-code HEAD").! == 0) {
            Process("git archive -o sample-scala.zip --prefix=sample-scala/ HEAD").!!
            IO.createDirectory(base / "sample-scala")
            IO.copyFile(base / "sample-scala.jar", base / "sample-scala" / "sample-scala.jar")
            IO.copyFile(base / "sample-scala.jar.pack.gz", base / "sample-scala" / "sample-scala.jar.pack.gz")
            Process("zip sample-scala.zip sample-scala/sample-scala.jar sample-scala/sample-scala.jar.pack.gz").!!
            IO.delete(base / "sample-scala")
        }
        else {
            s.log.warn("working tree not clean; no zip archive made")
            IO.delete(base / "sample-scala.zip")
        }
        jar
}

cleanFiles <++= baseDirectory { base =>
    Seq(base / "sample-scala.jar",
        base / "sample-scala.jar.pack.gz",
        base / "sample-scala.zip") }

I have an project/assembly.sbt with the contents:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.1")

I have a assembly.sbt in root with the contents:

import sbtassembly.AssemblyKeys._

baseAssemblySettings

In my scala code I have:

val configString = ConfigFactory.parseString(
        """
          akka {

            loglevel = "INFO"
            actor {

              provider = "akka.remote.RemoteActorRefProvider"
            }
            remote {

              enabled-transports = ["akka.remote.netty.tcp"]
              netty.tcp {

                hostname = "127.0.0.1"
                port = "9500"
              }

              log-sent-messages = on
              log-received-messages = on
            }
          }
        """.stripMargin)

val config = ConfigFactory.load(configString)

The resources folder contains an application.conf which I don't use at the moment. Greping the output of jar tf command with the expression "reference", clearly shows that reference.conf is present:

enter image description here

How do I package this akka example for a netlogo extension?

Note: I have included akka-actor and akka-remote as library dependencies. I am using Intellij and SBT 0.13.8 on a OS X platform.

EDIT: After taking the advice from Ayush, I get the following output from the command sbt assembly, however the same exception is still present:

enter image description here

Upvotes: 2

Views: 131

Answers (2)

Andrew Norman
Andrew Norman

Reputation: 911

there's an extra trick to solving this with newer akka libraries as akka does not include all their default configurations in the resource.conf

https://stackoverflow.com/a/72325132/1286583

Upvotes: 0

ayush
ayush

Reputation: 14578

I think the problem is that while using sbt:assembly the default merge strategy excludes all the reference.conf files. This is what i found in documentation.

If multiple files share the same relative path (e.g. a resource named application.conf in multiple dependency JARs), the default strategy is to verify that all candidates have the same contents and error out otherwise.

Can you try adding a MergeStrategy as follows

assemblyMergeStrategy in assembly := {
  case PathList("reference.conf") => MergeStrategy.concat
}

Upvotes: 1

Related Questions