sbt publish generates html instead of class - scala

I have a scala library that i'm packaging with sbt, in my local bash, i can publish it succesfully to nexus, but when i use gitlab ci/cd with same command (sbt publish) the generated jar contains only html files:
here's my build.sbt:
organization := "com.example"
name := "liblib"
version := "1.0"
publishTo := Some("nexus" at "nexus/repo")
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
and my gitlab.ci
package:
stage: build
image: scala-sbt:8u312_1.5.5_2.12.15
script:
# Build
- sbt clean test:compile
# Test
- sbt coverage test
- sbt coverageReport
- mv target target-for-sonar
# Package
- sbt clean compile package
artifacts:
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
paths:
- target
- target-for-sonar
expire_in: 1 week
publish:
stage: publish
image: scala-sbt:8u312_1.5.5_2.12.15
script:
- sbt publish
rules:
- when: manual

Related

SBT Native Packager change output location of ZIP

This is my build.sbt:
name := "DB-Services"
version := "0.1"
scalaVersion := "2.12.12"
lazy val root = (project in file(".")).enablePlugins(UniversalPlugin,JavaServerAppPackaging)
artifactName := { (_, _, _) => "DB-Services.zip"}
Universal / mappings ++= directory(target.value)
Currently sbt package generates DB-Services.zip inside of target/scala-2.12. However I need this ZIP to be generated inside target folder instead. But the problem is that the mapping I provided above does not work and the ZIP continues to be generated inside target/scala-2.12.
What changes should I do in my build.sbt so that the ZIP is generated in target folder? (I cannot generate the ZIP in any other location due to limitations with our CICD)
(PS: This answer does not work, so please do not mark this as duplicate)
Universal / target := (Compile / target).value
Works for me. How I found this:
There is a useful tool in SBT to dive into settings and tasks: inspect
I ran inspect root/Universal/packageBin (root/Universal/packageBin is how we build an artifact), it returned:
...
[info] Dependencies:
[info] Universal / packageBin / validatePackage
[info] Universal / packageBin / mappings
[info] Universal / packageName
[info] Universal / target
[info] Universal / packageBin / universalArchiveOptions
[info] Universal / topLevelDirectory
...
Universal / target looked interesting, so I ran: inspect Universal / target , it returned:
...
[info] Description:
[info] Main directory for files generated by the build.
...
We can find that Compile / target returns a path to the target directory in a same way (or just a read docs).

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

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.

How to disable running tests in sbt publishLocal

How do we disable running tests for sbt publishLocal ?
To disable running tests in assembly the following has been suggested (though I have seen it not working as well..):
sbt 'set test in assembly := {}' assembly
What about for publishLocal ? The following have all been attempted .. yet the tests always are run:
sbt 'set test in publish := {}' publishLocal
sbt 'set test in publishLocal := {}' publishLocal
sbt 'set test in assembly := {}' publishLocal

How to exclude resources during packaging with SBT but not during testing

I have a bunch of conf files in a project structure like this:
```
src / main / resources / live.conf
src / test / resources / test.conf
```
I want to excluded live.conf from the artifact that is build when I run sbt one-jar (using the one-jar plugin). I added this line which unfortunately also excludes test.conf when running sbt test:compile
excludeFilter in Runtime in unmanagedResources := "*.conf"
How can I exclude live.conf in the artifact jar but not for the tests?
This should help:
mappings in (Compile, packageBin) ~= { _.filter(!_._1.getName.endsWith(".conf")) }
packageBin is a task which produces your jar artifact and mappings denotes files wich are used for compilation and project packaging in Compile scope

Compile tests with SBT and package them to be run later

Im working with SBT and Play! Framework. Currently we have a commit stage in our pipeline where we publish to artifactory our binaries. The binaries are generated with the dist task. The pipeline then runs smoke and acceptance tests that are written in scala. They are run with sbt.
What I want to do is to compile the smoke and acceptance tests as well as the binary and publish them to artifactory. That will allow the pipeline to download these binaries (the test suites) and run them, instead of recompiling them every time, which takes a long time.
I tried sbt test:compile which generates the jar, but then I cant find a way to run the tests.
sbt dont publish test in artifacts
publishArtifact in GlobalScope in Test:== false
source: https://github.com/sbt/sbt/blob/a7413f6415687f32e6365598680f3bb8545c46b5/main/src/main/scala/sbt/Defaults.scala#L1118
this is how to enable it
// enable publishing the jar produced by `test:package`
publishArtifact in (Test, packageBin) := true
// enable publishing the test API jar
publishArtifact in (Test, packageDoc) := true
// enable publishing the test sources jar
publishArtifact in (Test, packageSrc) := true
source: http://www.scala-sbt.org/release/docs/Detailed-Topics/Artifacts
run the test
scala -classpath pipeline.jar classpath scalatest-<version>.jar org.scalatest.tools.Runner -p compiled_tests
where pipeline.jar is the test artifact you receive from the pipeline
or you can setup a test projet via sbt
http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing.html