Problems with cross building a library

I am currently trying to port a library to ScalaJS, and I have some problems with the execution. I use CrossProject in my attempt (as I guess is mandatory). And if you look at the Project here. You can see, that the project is split into two sub-projects and both are targeted for cross-compilation.
Here is the essentiam part of the build.sbt:

name := "ezXML"
enablePlugins(ScalaJSJUnitPlugin)

ThisBuild / organization := "com.github.julienst"
ThisBuild / version := "0.2"
ThisBuild / scalaVersion := "2.13.2"

lazy val core = crossProject(JSPlatform, JVMPlatform)
    .crossType(CrossType.Pure)
    .in(file("core"))
    .settings(
        name := "ezxml.core",
        libraryDependencies := Seq (
            "org.scala-lang.modules" %%% "scala-xml" % "1.3.0", // https://mvnrepository.com/artifact/org.scala-lang.modules/scala-xml
            "junit" % "junit" % "4.13" % Test, // https://mvnrepository.com/artifact/junit/junit
            "org.scalatest" %%% "scalatest" % "3.1.2" % Test // https://mvnrepository.com/artifact/org.scalatest/scalatest
        )
    )

lazy val extension = crossProject(JSPlatform, JVMPlatform)
    .crossType(CrossType.Pure)
    .in(file("extension"))
    .dependsOn(core)
    .settings(
        name := "ezxml.extension",
        libraryDependencies := Seq (
            "org.scala-lang.modules" %%% "scala-xml" % "1.3.0", // https://mvnrepository.com/artifact/org.scala-lang.modules/scala-xml
            "org.scala-lang" % "scala-reflect" % "2.13.2", // https://mvnrepository.com/artifact/org.scala-lang/scala-reflect
            "junit" % "junit" % "4.13" % Test, // https://mvnrepository.com/artifact/junit/junit
            "org.scalatest" %%% "scalatest" % "3.1.2" % Test // https://mvnrepository.com/artifact/org.scalatest/scalatest
        ),
        scalacOptions += "-Ymacro-annotations"
    )

lazy val root = crossProject(JSPlatform, JVMPlatform)
    .crossType(CrossType.Pure)
    .in(file("."))
    .aggregate(core, extension)

And here is the project-structure
root
|–> core
|------> .js (w\ code)
|------> .jvm (w\ code)
|------> src (with all the code)
|–> extension
|------> .js (with some code)
|------> .jvm (with some code)
|------> src (with some code)

Here are my issues:

The Tests in extension/.jvm are not being executed and instead I get the following

[IJ]sbt:ezXML> extensionJVM/test
[info] Run completed in 19 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[success] Total time: 1 s, completed 17.06.2020, 20:42:07

I am not really sure what I am doing wrong, since the core.jvm is executing and passing all test

The Tests for JS were also not executing. There all I get is this:

[error] There were linking errors
[error] There were linking errors
[error] (extensionJS / Test / fastOptJS) There were linking errors
[error] (coreJS / Test / fastOptJS) There were linking errors

Am I even correct in my assumption, that the code in .js and .jvm can be completely different – even different packages – or are these directories just used as overwrites for classes existing in src. I don’t really know what to search for on this matter and looking at other projects didn’t help me out either (maybe I just didn’t look at the right one)

Thank you very much for your help!

1 Like

I got 1 and 3 working. Both were related to the structure.
Before it looked like this:
root
|–> core
|------> .js
|--------------> main
|--------------> test

But it had to be:

root
|–> core
|------> .js (w\ code)
|--------------> src
|----------------------> main
|----------------------> test

The change in project structure resolved both 1 and 3. However, 2 is still unresolved. In IDEA I can run the tests as JVM tests, which is somewhat useful, but not really as it should be. If somebody can tell me what is going on, that would be really helpful.