org.scalajs.sbtplugin.cross

CrossProject

final class CrossProject extends AnyRef

A convenience structure that creates a JVM and a Scala.js project under the hood and forwards common operations to it.

Basic Usage

In your build.sbt, use CrossProject as follows:

lazy val p1 = crossProject.
  settings(
    name := "test", // default name would be p1
    libraryDependencies += "org.example" %%% "test" % "0.1"
  ).
  jvmSettings(
    libraryDependencies += "org.example" %% "jvm-specific" % "0.1"
  ).
  jsSettings(
    libraryDependencies += "org.example" %%% "js-specific" % "0.1",
    jsDependencies += "org.example" %% "js-thing" % "0.1" / "foo.js"
  )

// Needed, so sbt finds the projects
lazy val p1JVM = p1.jvm
lazy val p1JS = p1.js

lazy val p2 = crossProject.crossType(CrossType.Pure).dependsOn(p1 % "test")

// Needed, so sbt finds the projects
lazy val p2JVM = p2.jvm
lazy val p2JS = p2.js

CrossProject types

There are three built-in types of CrossProjects. Each of them corresponds to a concrete subclass of CrossType:

Full CrossProject (CrossType.Full)

A CrossProject that has both shared and individual JVM/JS sources. This is the default.

The directory structure is as follows:

 project/
   shared/
     src/
       main/
       test/
   jvm/
     src/
       main/
       test/
   js/
     src/
       main/
       test/

The shared source tree is included in both the JVM and the JS project.

Pure CrossProject (CrossType.Pure)

A CrossProject that does not have individual JVM/JS sources.

The directory structure is as follows:

 project/
   src/
     main/
     test/
   .jvm/
   .js/

The source tree is included in both the JVM and the JS project. The hidden folders are the true project roots in sbt's terms.

Dummy CrossProject (CrossType.Dummy)

A CrossProject that does not have shared JVM/JS sources. It is useful, since it can still be used for dependency tracking and aggregation.

The directory structure is as follows:

 project/
   jvm/
     src/
       main/
       test/
   js/
     src/
       main/
       test/

Eclipse Support

Note that by default, the sbteclipse plugin uses sbt's project names to name the Eclipse projects it generates. Since the CrossProject generates two projects with the same name, this may result in a conflict when importing the projects into Eclipse.

You can configure sbteclipse to use the project ID instead (which is unique in sbt as well):

EclipseKeys.useProjectId := true

Alternatively, you can of course also just import one of the two projects into your Eclipse.

IntelliJ IDEA Support

While CrossProject works out of the box with Eclipse and the sbt eclipse plugin, it does not with IntelliJ IDEA due to its missing support for shared source directories.

To fix this, you should add symlinks in the hierarchy to the shared source directory and include them in your imported IntelliJ IDEA project (but not in sbt). The recommended structure is as follows (for a Full CrossProject):

 project/
   shared/
     src/
       main/
       test/
   jvm/
     src/
       main/
       test/
       idea-shared-main/ --> project/shared/src/main
       idea-shared-test/ --> project/shared/src/test
   js/
     src/
       main/
       test/
       idea-shared-main/ --> project/shared/src/main
       idea-shared-test/ --> project/shared/src/test

Note that we do not recommend to put the symlinks in version control, since they do not work on Windows (Git, for example, just ignores their existence when cloning).

Pitfalls to Avoid

Altering a contained Project outside the CrossProject

Since sbt projects are immutable structures, it is important that you do not "mutate" (i.e. create a new Project) outside of the CrossProject.

DON'T
lazy val p1 = crossProject

lazy val p1JVM = p1.jvm
lazy val p1JS = p1.js.settings(jsDependencies += RuntimeDOM)

// Now we have p1JS != p1.js... Dependency tracking will not work anymore.
DO
lazy val p1 = crossProject.
  jsSettings(jsDependencies += RuntimeDOM)

lazy val p1JVM = p1.jvm
lazy val p1JS = p1.js
Manually setting the base of a contained Project

CrossProject puts its contained projects in a given directory structure. If you try to work around that, things will fail (and non-existing directories will be referenced). If you want to put your projects in a different directory structure, you are encouraged to implement your own subclass of CrossType.

DON'T
lazy val p1 = crossProject.jsConfigure(_.in(file("myJSDir")))
DO

Implement your own subclass (sub-object) of CrossType.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. CrossProject
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def aggregate(refs: CrossProject*): CrossProject

  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def configs(cs: Configuration*): CrossProject

  10. def configureAll(transforms: (Project) ⇒ Project*): CrossProject

  11. def configureCross(transforms: (CrossProject) ⇒ CrossProject*): CrossProject

  12. def dependsOn(deps: CrossClasspathDependency*): CrossProject

  13. def disablePlugins(ps: AutoPlugin*): CrossProject

  14. def enablePlugins(ns: Plugins*): CrossProject

  15. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  17. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  18. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  19. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  20. def in(dir: File): CrossProject

  21. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  22. val js: Project

  23. def jsConfigure(transformer: (Project) ⇒ Project): CrossProject

    Transform the underlying JS project

  24. def jsSettings(ss: sbt.Def.Setting[_]*): CrossProject

    Add settings specific to the underlying JS project

  25. val jvm: Project

  26. def jvmConfigure(transformer: (Project) ⇒ Project): CrossProject

    Transform the underlying JVM project

  27. def jvmSettings(ss: sbt.Def.Setting[_]*): CrossProject

    Add settings specific to the underlying JVM project

  28. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  29. final def notify(): Unit

    Definition Classes
    AnyRef
  30. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  31. def overrideConfigs(cs: Configuration*): CrossProject

  32. def settingSets(select: AddSettings*): CrossProject

    Configures how settings from other sources, such as .

    Configures how settings from other sources, such as .sbt files, are appended to the explicitly specified settings for this project.

    Note: If you disable AutoPlugins here, Scala.js will not work

  33. def settings(ss: sbt.Def.Setting[_]*): CrossProject

  34. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  35. def toString(): String

    Definition Classes
    CrossProject → AnyRef → Any
  36. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  37. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def configure(transforms: (CrossProject) ⇒ CrossProject*): CrossProject

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.10) Use configureCross instead.

Inherited from AnyRef

Inherited from Any

Ungrouped