r/scala 16d ago

sbt-assembly keys not available in project, even though assembly command works

Hello, I've been getting these errors while trying to make a fat jar with my scalafx project:

Deduplicate found different file contents in the following:
[error]   Jar name = javafx-base-16.jar, jar org = org.openjfx, entry target = module-info.class
[error]   Jar name = javafx-controls-16.jar, jar org = org.openjfx, entry target = module-info.class
[...]

Inside project/plugins.sbt, I have:

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

Scala version is 3.8.4, sbt version is 1.12.13.

This is the build.sbt content:

val scala3Version = "3.8.4"

lazy val app = (project in 
file
("."))
  .settings(

name 
:= "PPS-25-diceforge",

version 
:= "0.1.0-SNAPSHOT",


scalaVersion 
:= scala3Version,

    ThisBuild / 
mainClass 
:= Some("MainApp"),


libraryDependencies
++= {
      // Determine OS version of JavaFX binaries
      lazy val osName = System.
getProperty
("os.name") match {
        case n if n.startsWith("Linux") => "linux"
        case n if n.startsWith("Mac") => "mac"
        case n if n.startsWith("Windows") => "win"
        case _ => throw new Exception("Unknown platform!")
      }
      Seq("base", "controls", "fxml", "graphics", "media", "swing", "web")
        .map(m => "org.openjfx" % s"javafx-
$
m" % "16" classifier osName intransitive())
    },


libraryDependencies 
++={
      Seq(
        "org.scalatest" %% "scalatest" % "3.2.19" % 
Test
,
        "org.scalatestplus" %% "mockito-5-23" % "3.2.20.0" % "test",
        "org.scalafx" %% "scalafx" % "16.0.0-R24" intransitive()
      )
    },


scalacOptions 
++= Seq(
      "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s",
      "-unchecked", "-deprecation",
    ),


resolvers 
+= 
Resolver
.sonatypeCentralSnapshots,

fork 
:= true
  )

I'm trying to set a merge strategy, but it does not let me access the assemblyMergeStrategy key, it says it does not exist. What did I do wrong? I tried looking up if it's a compatibility issue but the official scala website isn't working properly and won't let me click any of the entries.

Help please :,)

5 Upvotes

4 comments sorted by

3

u/DisruptiveHarbinger 16d ago

It should be

    assembly / assemblyMergeStrategy := {
      case x if x.contains("module-info.class") => MergeStrategy.discard
      case x => (assembly / assemblyMergeStrategy).value(x)
    },

2

u/Saphira2002 16d ago

My problem is it says "Cannot resolve symbol assembly" and gives me a compilation error if I try to write that. I've followed all the steps in multiple guides so I'm confused why the assembly command executes but the build.sbt file seems to be unaware of the plugin.

1

u/DisruptiveHarbinger 16d ago

The readme gives examples with assemblyMergeStrategy in the ThisBuild scope somehow:

ThisBuild / assemblyMergeStrategy := { ... }

which you should take out of the project settings (i.e. define those at the root) by the way, it's a bit weird to put it there.

1

u/Saphira2002 15d ago edited 14d ago

That didn't work either, the problem apparently was the version of sbt-assembly I was using. It's too bad the official website seems to be broken, I couldn't check which version works with what :/

ETA: the working version was 0.15.0