cross-build artifacts being built but not with `releaseCrossBuild := true` - scala

I'm trying to release a version of https://github.com/guardian/marley cross-built for Scala v2.11 & v2.12. All code dependencies are satisfied, and both +test and +publishLocalSigned work as expected, the latter definitely producing artifacts for Scala v2.11 & v2.12. Unfortunately, executing sbt release with the sbt-sonatype plugin only uploads artifacts for Scala v2.12 - it makes no attempt to upload artifacts for Scala v2.11 to the sonatype staging repository.
Here are the relevant sbt settings from the build.sbt file (full version in the repo on GitHub):
scalaVersion in ThisBuild := "2.12.4"
crossScalaVersions in ThisBuild := Seq(scalaVersion.value, "2.11.12")
import ReleaseTransformations._
releaseCrossBuild := true // true if you cross-build the project for multiple Scala versions
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
releaseStepCommand("publishSigned"),
setNextVersion,
commitNextVersion,
releaseStepCommand("sonatypeReleaseAll"),
pushChanges
)
Here's a full copy of the sbt release command output: https://gist.github.com/rtyley/5f9f832fabe2bdcfc2d561a36c29f993 - you can see that even though [info] Setting scala version to 2.11.12 occurs (twice) - only Scala 2.12 artifacts are uploaded.

I think the issue is the releaseStepCommand("publishSigned") in your release process.
I think either:
it needs to be releaseStepCommand("+publishSigned"); or
you need to instead set releasePublishArtifactsAction := PgpKeys.publishSigned.value, and switch back to publishArtifacts (instead of using releaseStepCommand)
The README documents the releasePublishArtifactsAction way.

Related

SBT: compile & package -- "working tree not clean"

I am working on a Scala extension for NetLogo (repo). I am following both the Extension API example and NetLogos Sample-Scala-Extension.
I am seeing:
[info] Done packaging.
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>
[warn] working tree not clean when packaging; target not created
[success] Total time: 6 s, completed Jan 29, 2019, 6:22:00 PM
The .jar that is generated does not contain modifications I made to the extension. I think it has something to do with "[warn] working tree not clean...".
Is this the case?
What is the solution?
File hierarchy:
Scala-Plume-Model
build.sbt
src
PlumeModelExtension.scala
build.sbt
enablePlugins(org.nlogo.build.NetLogoExtension)
name := "plume-scala"
version := "0.1"
scalaVersion := "2.12.0"
netLogoExtName := "plume-scala"
netLogoClassManager := "PlumeModelExtension"
netLogoZipSources := false
scalaSource in Compile := baseDirectory.value / "src"
scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xfatal-warnings", "-encoding", "us-ascii")
netLogoVersion := "6.0.4"
The short answer: add isSnapshot := true to your build.sbt and then the package sbt task should start creating the output jar and zip files regardless of the current status of git.
Longer answer: The NetLogo Extension SBT plugin has some expectations about when packaging will occur. If isSnapshot is false or unset, the plugin assumes you're trying to do a "production" release. But for a production release you probably do not want to compile and package off of a dirty repository. So it warns you and does not create the artifacts.
The normal workflow would be to keep isSnapshot := true while you're in development, then once you have all your commits done and are ready for a release, add a commit to set isSnapshot := false (maybe along with a version bump for the extension), package and tag the release, then add a commit setting isSnapshot := true right away.

Maven JAR file only includes HTML files, not Scala classes

I followed this guide to release a Scala / SBT JAR file in Maven.
I ran the sbt publishSigned and sbt sonatypeRelease for the spark-fast-tests 0.11.0 release and the JAR file was correctly built. See here. These commands come from the sbt-sonatype plugin.
For some reason, when I did the 0.12.0 release, the Maven JAR file only includes HTML files and images. For example, the downloaded JAR file contains this file com/github/mrpowers/spark/fast/tests/DatasetComparer.html, but doesn't include DatasetComparer.class.
The target/scala-2.11/spark-fast-tests_2.11-2.3.0_0.12.0.jar file also only includes the HTML files (either sbt publishSigned or sbt sonatypeRelease must have generated this JAR file).
When I run sbt package, the JAR file that's generated includes the Scala classes like com/github/mrpowers/spark/fast/tests/DatasetComparer.class, as expected.
spark-fast-tests is an open source project and here is the build.sbt file.
How can I include my project classes in the JAR file that's uploaded to Maven? Any tips / tricks on how to debug this better?
Analysing spark-fast-tests build.sbt I would make the following recommendations:
Add sbt-release to plugins.sbt to enable release process customisation:
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.8")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
Create version.sbt at project root and move version setting out of build.sbt:
version in ThisBuild := "0.12.1-SNAPSHOT"
Create sonatype.sbt at project root and move the following settings out of build.sbt:
homepage := Some(url("https://github.com/mrpowers/spark-fast-tests/"))
scmInfo := Some(
ScmInfo(
url("https://github.com/mrpowers/spark-fast-tests/"),
"git#github.com:mrpowers/spark-fast-tests.git"
)
)
developers := List(
Developer(
"mrpowers",
"Matthew Powers",
"matthewkevinpowers#gmail.com",
url("https://github.com/mrpowers/spark-fast-tests/")
)
)
licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
publishMavenStyle := true
Add the following release settings to build.sbt:
import sbtrelease.ReleaseStateTransformations._
publishTo := Some(
if (isSnapshot.value) { Opts.resolver.sonatypeSnapshots }
else { Opts.resolver.sonatypeReleases }
)
releasePublishArtifactsAction := PgpKeys.publishSigned.value
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
publishArtifacts,
setNextVersion,
commitNextVersion,
releaseStepCommand("sonatypeReleaseAll"),
pushChanges
)
Release to Maven Central with sbt release
For a working example have a look at build configuration of sbt-sonatype itself.
A little late to the party, but I had the same problem with spark-testing-base.
It stems from the way you modify the artifactName:
artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
artifact.name + "-" + module.revision + "." + artifact.extension
}
which is probably copied from the official SBT docs.
Note that the docs have the following hint below the code though:
(Note that in practice you rarely want to drop the classifier.)
My solution for spark-testing-base is the following:
artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
Artifact.artifactName(sv, module, artifact).replaceAll(s"-${module.revision}", s"-${sparkVersion.value}${module.revision}")
}
This should make sure to keep the classifier (and whatever additional things might go into the artifactName) and solved the problem of JAR files containing documentation instead of class files.

sbt console - set scala-version for all sub-projects

I have a multi-project build with scalaVersion := "2.11.8" for each module.
I want to run test and publish-local for Scala 2.12.0-RC1 without touching the build file. I thought the following would work:
$ sbt
> set scalaVersion in ThisBuild := "2.12.0-RC1"
> test
But that does not alter the Scala version used, sbt still compiles with Scala 2.11.8. This only works for single module builds (without project definitions).
How do I effectively override scalaVersion for all sub-modules from the sbt console?
Your attempt doesn't work because the setting for the module takes priority over the setting for ThisBuild; it would work if you used scalaVersion in ThisBuild in the build file instead of setting it separately for each module. I don't know if there is a way to do this with anything except scalaVersion, but:
As a final note, you can use ++ to temporarily switch the Scala version currently being used to build. should be either a version for Scala published to a repository, as in ++ 2.10.0 or the path to a Scala home directory, as in ++ /path/to/scala/home. See Command Line Reference for details.
> ++2.12.0-RC1
> test

how to configure 2.9.1 in org.scala-sbt#sbt_2.9.1;0.12.3

I am trying a very simple sbt example; when I compile it with sbt, and always get the following error:
org.scala-sbt#sbt_2.9.1;0.12.3: not found
I found a build.properties file under project folder, where I could change the 0.12.3 part; for example, after I changed it to 0.11.3, it will succeed until another inompatible issue; However, I want to know how to change sbt_2.9.1 to, say, sbt_2.9.2; I don't find a configuration file, and even I update the sbt to the latest version 0.12.3, still no luck.
my build.sbt file:
organization := "com.typesafe.slick"
name := "slick-examples"
version := "1.0.1-RC1"
scalaVersion := "2.10.1"
scalacOptions += "-deprecation"
anyone please help me.
The Scala version sbt is using internally and the one used for your project are totally independent. Which sbt launcher are you using? Make sure you are using an sbt.version property that works for your sbt launcher.
Again, no need to configure the Scala version for your project at that level. Write a build.sbt file and set scalaVersion to, e.g. 2.10.1 (assuming you use sbt 0.12.x): scalaVersion := 2.10.1

How does sbt choose which Scala version to use?

I have multiple projects in my sbt build. I'm trying to upgrade to Scala 2.10 from 2.9.1, so in my build.sbt file I put
scalaVersion := "2.10.0"
This seemed to work, because in my top-level project in sbt I get:
> scala-version
[info] 2.10.0
However, when I switch to one of the other projects:
> project web-client
[info] Set current project to web-client (in build file:/C:/Users/...
[web-client] $ scala-version
[info] 2.9.1
You see the version has now changed back to 2.9.1! How do I force the same Scala version to be used across all my projects?
I found out scoping the scalaVersion to ThisBuild will set it for all sub-projects. Details are here: http://www.scala-sbt.org/release/docs/Getting-Started/Multi-Project.html at the bottom, but here is what it says:
To set it only once, it is enough to write, in the main build.sbt file, the following line:
scalaVersion in ThisBuild := "2.10.0"
SBT has a default Scala version. You need to add the scalaVersion setting to all subprojects if you wish to change it. The most common way of doing that is having a "common settings" value that is added to all projects at the root level, through project/Build.scala.