All Projects → portable-scala → Sbt Crossproject

portable-scala / Sbt Crossproject

Licence: bsd-3-clause
Cross-platform compilation support for sbt.

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Sbt Crossproject

Sbt Jacoco
JaCoCo Code Coverage plug-in for sbt.
Stars: ✭ 115 (-34.66%)
Mutual labels:  sbt, sbt-plugin
Gatling Sbt Plugin Demo
Showcase of the Gatling Plugin for SBT
Stars: ✭ 137 (-22.16%)
Mutual labels:  sbt, sbt-plugin
Sbt Multi Jvm
Multi-JVM testing in sbt
Stars: ✭ 50 (-71.59%)
Mutual labels:  sbt, sbt-plugin
Stryker4s
Mutation testing for Scala. Work in progress...
Stars: ✭ 118 (-32.95%)
Mutual labels:  sbt, sbt-plugin
Sbt Protobuf
sbt plugin for compiling protobuf files
Stars: ✭ 163 (-7.39%)
Mutual labels:  sbt, sbt-plugin
Sbt Ignore Play Generated
Configure linters and coverage tools to ignore Play's generated source files.
Stars: ✭ 10 (-94.32%)
Mutual labels:  sbt, sbt-plugin
Sbt Unidoc
sbt plugin to create a unified API document across projects
Stars: ✭ 113 (-35.8%)
Mutual labels:  sbt, sbt-plugin
Sbt Buildinfo
I know this because build.sbt knows this.
Stars: ✭ 486 (+176.14%)
Mutual labels:  sbt, sbt-plugin
Sbt Prompt
An SBT plugin for making your SBT prompt more awesome
Stars: ✭ 107 (-39.2%)
Mutual labels:  sbt, sbt-plugin
Flyway Sbt
Flyway SBT plugin
Stars: ✭ 101 (-42.61%)
Mutual labels:  sbt, sbt-plugin
Sbt Docker
Create Docker images directly from sbt
Stars: ✭ 689 (+291.48%)
Mutual labels:  sbt, sbt-plugin
Sbt S3 Resolver
☁️Amazon S3-based resolver for sbt
Stars: ✭ 112 (-36.36%)
Mutual labels:  sbt, sbt-plugin
Sbt Updates
sbt plugin that can check Maven and Ivy repositories for dependency updates
Stars: ✭ 653 (+271.02%)
Mutual labels:  sbt, sbt-plugin
Sbt Play Gulp
Gulp asset pipeline for Play Framework
Stars: ✭ 38 (-78.41%)
Mutual labels:  sbt, sbt-plugin
Sbt Release
A release plugin for sbt
Stars: ✭ 582 (+230.68%)
Mutual labels:  sbt, sbt-plugin
Sbt Frege
Frege support for sbt
Stars: ✭ 51 (-71.02%)
Mutual labels:  sbt, sbt-plugin
Soteria
Plugin to block compilation when unapproved dependencies are used or code styling does not comply.
Stars: ✭ 36 (-79.55%)
Mutual labels:  sbt, sbt-plugin
Xsbt Web Plugin
Servlet support for sbt
Stars: ✭ 381 (+116.48%)
Mutual labels:  sbt, sbt-plugin
Sbt Dependency Graph
sbt plugin to create a dependency graph for your project
Stars: ✭ 1,223 (+594.89%)
Mutual labels:  sbt, sbt-plugin
Sbt Native Packager
sbt Native Packager
Stars: ✭ 1,480 (+740.91%)
Mutual labels:  sbt, sbt-plugin

sbt-crossproject

Join the chat at https://gitter.im/scala-native/sbt-crossproject

Build Status

Cross-platform compilation support for sbt.

Requirements:

  • sbt 1.2.1+
  • For JSPlatform: Scala.js 0.6.23+ or 1.0.0+
  • For NativePlatform: Scala Native 0.3.7+

If you are still using sbt 0.13.x, you must use sbt-crossproject v0.6.1 instead of v1.0.0.

Installation

Cross-Compiling Scala.js, JVM and Native

In project/plugins.sbt:

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject"      % "1.0.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
addSbtPlugin("org.scala-js"       % "sbt-scalajs"                   % "1.0.0")
addSbtPlugin("org.scala-native"   % "sbt-scala-native"              % "0.3.7")

In build.sbt:

// If you are using Scala.js 0.6.x, you need the following import:
//import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

val sharedSettings = Seq(scalaVersion := "2.11.12")

lazy val bar =
  // select supported platforms
  crossProject(JSPlatform, JVMPlatform, NativePlatform)
    .crossType(CrossType.Pure) // [Pure, Full, Dummy], default: CrossType.Full
    .settings(sharedSettings)
    .jsSettings(/* ... */) // defined in sbt-scalajs-crossproject
    .jvmSettings(/* ... */)
    // configure Scala-Native settings
    .nativeSettings(/* ... */) // defined in sbt-scala-native

// Optional in sbt 1.x (mandatory in sbt 0.13.x)
lazy val barJS     = bar.js
lazy val barJVM    = bar.jvm
lazy val barNative = bar.native

lazy val foo =
  crossProject(JSPlatform, JVMPlatform, NativePlatform)
    .settings(sharedSettings)
    .settings(
      // %%% now include Scala Native. It applies to all selected platforms
      libraryDependencies += "org.example" %%% "foo" % "1.2.3"
    )

// Optional in sbt 1.x (mandatory in sbt 0.13.x)
lazy val fooJS = foo.js
lazy val fooJVM = foo.jvm
lazy val fooNative = foo.native

Removing the platform suffix for one "default" platform

If you mainly use one "default" platform in your everyday development, you can tell sbt-crossproject not to add the platform suffix to its project ID. For example, assuming you mainly compile and test for the JVM, you can write:

lazy val bar =
  crossProject(JSPlatform, JVMPlatform, NativePlatform)
    .withoutSuffixFor(JVMPlatform)
    .crossType(...)
    .settings(...)

// Optional in sbt 1.x (mandatory in sbt 0.13.x)
lazy val barJS     = bar.js
lazy val barJVM    = bar.jvm
lazy val barNative = bar.native

The call to withoutSuffixFor must come first after the call to crossProject(), otherwise it will not compile.

Now, in the sbt prompt, you can do

> bar/test

to test the JVM platform (instead of barJVM/test). This of course applies to all tasks.

Note that inside the build, you still need to use barJVM to the JVM Project. withoutSuffixFor only changes the id of the project, which is used in the sbt prompt.

Detecting the current platform in a project's settings

Within the settings of a crossProject, you can detect the platform for which those settings are being applied to with crossProjectPlatform. Here is a contrived example:

lazy val bar =
  crossProject(JSPlatform, JVMPlatform, NativePlatform)
    .crossType(...)
    .settings(
      name := "bar for " + crossProjectPlatform.value.identifier
    )

...

Cross-Compiling JVM and Native

In project/plugins.sbt:

addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
addSbtPlugin("org.scala-native"   % "sbt-scala-native"              % "0.3.7")

In build.sbt:

val sharedSettings = Seq(scalaVersion := "2.11.12")

lazy val bar =
  // select supported platforms
  crossProject(JVMPlatform, NativePlatform)
    .settings(sharedSettings)
    // configure JVM settings
    .jvmSettings(/* ... */)
    // configure Scala-Native settings
    .nativeSettings(/* ... */) // defined in sbt-scala-native

// Optional in sbt 1.x (mandatory in sbt 0.13.x)
lazy val barJVM    = bar.jvm
lazy val barNative = bar.native

Migration from Scala.js 0.6.x' default crossProject

We carefully implemented sbt-crossproject to be mostly source compatible with Scala.js crossProject

In project/plugins.sbt:

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("org.scala-js"       % "sbt-scalajs"              % "0.6.23")

In build.sbt:

// shadow sbt-scalajs' crossProject and CrossType from Scala.js 0.6.x
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

lazy val bar =
  // select supported platforms
  crossProject(JSPlatform, JVMPlatform)
    .crossType(CrossType.Pure) // [Pure, Full, Dummy], default: CrossType.Full
    .settings(/* ... */)
    .jsSettings(/* ... */) // defined in sbt-scalajs-crossproject
    .jvmSettings(/* ... */)

// Optional in sbt 1.x (mandatory in sbt 0.13.x)
lazy val barJS = bar.js
lazy val barJVM = bar.jvm

When using Build.scala

import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType, _}
import scalajscrossproject.ScalaJSCrossPlugin.autoImport._
import scalanativecrossproject.ScalaNativeCrossPlugin.autoImport._

Configuration

CrossTypes

Setting a specific CrossType allows the definition of a custom source tree layout for managing native-, js- and jvm-specific sources in directories of their own.

sbt-cross provides by default 3 implementations of the CrossType class that one can pass as .crossType parameter:

  • .crossType(CrossType.Pure):
.
├── .js
├── .jvm
├── .native
└── src

This layout is preferred for codebases which do not contain any platform-specific code.

Since this is the case of most existing sbt projects it is often desired during conversion to sbt-cross to place the cross-project at the root of the project source tree.

This can be done with the following set of options:

lazy val foo = crossProject.crossType(CrossType.Pure).in(file("."))

  • .crossType(CrossType.Full)
.
├── js
├── jvm
├── native
└── shared

This layout gives full control by providing a shared directory for common code.

  • .crossType(CrossType.Dummy)
.
├── js
├── jvm
└── native
  • .crossType({/*custom*/})

One can easily extend CrossType and provide a custom tree structure.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].