Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cannot use sbt-native-packager to build a setup for test classes #1157

Closed
liebichw opened this issue Sep 12, 2018 · 4 comments
Closed

I cannot use sbt-native-packager to build a setup for test classes #1157

liebichw opened this issue Sep 12, 2018 · 4 comments

Comments

@liebichw
Copy link

Expected behaviour

I wanted to use the sbt-native-packager plugin to create a setup for certain test classes (for internal use in our team).
I tried to use the method shown in https://stackoverflow.com/questions/31186204/how-to-add-a-project-test-jar-to-a-package/31367788#31367788 (i.e. add a mapping for the test-jar).

Actual behaviour

This works insofar as the "stage" command now also creates and adds the test jar. But it complains that no mainClass was found and thus no start script was created.
If I call "test/stage", the result is the same.
When I set the "mainClass in Compile" setting to the wanted class, a start script is created, but it fails because the test-jar is not present in this script's classpath!

Information

I am using

  • sbt-native-packager version 1.3.6
  • sbt version 1.1.6
  • I am running the build under gentoo linux
  • I just tried to get a "stage" working (an universal build is enough). A universal ZIP file with bash and cmd start scripts is fully enough for me.
@liebichw
Copy link
Author

I found newer plugin releases (strange - github tells me 1.3.6 is the latest release and offers me to show newer tags?), but the problem persisted also with the plugin version 1.3.9.

@muuki88
Copy link
Contributor

muuki88 commented Sep 13, 2018

Thanks for your detailed issue 🤗 This question is similar to #1136 I guess.

Your attempt doesn't work, because adding something to the mappings, doesn't add it to the classpath. These are two separate things. You can extend your solution like this

// adds the test jar to mappings
mappings in Universal += {
  // generates the test package
  val testjar = (packageBin in Test).value
  // maps this file to your lib folder in your output package
  testjar -> s"lib/${testjar.getName}"
},
scriptClasspath += (packageBin in Test).value.getName

If you inspect the scriptClasspath task you will see the description:

[info] Task: scala.collection.Seq[java.lang.String]
[info] Description:
[info] 	A list of relative filenames (to the lib/ folder in the distribution) of what to include on the classpath.

@muuki88 muuki88 closed this as completed Sep 13, 2018
@er1c
Copy link

er1c commented Jun 23, 2019

This approach works for a single project, but in a multi-project (e.g. https://github.com/muuki88/sbt-native-packager-examples/blob/master/multi-module-build/build.sbt) doesn't include any of the dependsOn test artifacts. Is it also possible to modify/give an example where the sbt test/stage produces a different result than simply sbt stage?

@er1c
Copy link

er1c commented Jun 23, 2019

I attempted to figure out one of my issues. But it doesn't look like it's supported?

Should something like this work?

mainClass in Compile := Some("com.foo.App"),
mainClass in Test := Some("org.scalatest.tools.Runner"),

Looks like it's hard coded to Compile here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants