How run sbt assembly command without tests from command line? - testing

I have read questions: this and that. They suggest to modify sbt file. But I want run sbt clean assembly without tests and do not modify sbt build files. Is it possible with sbt? In maven there is -DskipTest=true parameter, is there analog for sbt?

For any properties you need to change on the command line, prepend them with "set ", and wrap them in quotes.
Example for Windows:
sbt "set test in assembly := {}" clean assembly
Example for Mac:
sbt 'set test in assembly := {}' clean assembly

Related

"NoClassDefFoundError" when the jar file built by Intellij Idea artifacts was executed in command line

I have a problem with running my jar execution file built by Intellij Idea Artifacts in command line. Error message is
NoClassDefFoundError: io.mattmoore.kotlin.playground.cinterop.Greeter
But it worked when I use the IDE to execute "RUN".
Do you have any Idea why is that happening?
Highly appreciated if someone could give me a hint about how to fix it.
Harrison
IDE knows better where to find dependencies, but once you export .jar file, you need to manually ensure that no dependency is missing
(and that all get loaded).
Example:
To run MyProgram.jar, place all your dependencies inside of libs directory (which you need to create beside it), then use command like:
java -cp 'MyProgram.jar:libs/*' my_package.MyMainClass
OR for Windows (use semicolon)
java -cp 'MyProgram.jar;libs/*' my_package.MyMainClass
Note that dependency means other .jar files, for example, the one that defines io.mattmoore.kotlin.playground.cinterop.Greeter class.
See also How to call ".jar” with additional classpath option?

How to run sbt assembly on a module without test

I want to launch the following command and skip tests
sbt "project myModlule" clean assembly
I know this one for the full project
sbt 'set test in assembly := {}' clean assembly
But I don't know how to mix them in order to take into account just one module (myModule).
Do you have any idea?
Thanks to João Guitana who gave the anwser
sbt "project myModlule" "set test in assembly := {}" clean assembly

SBT can't read environment variables in IntelliJ

I defined a new environment variable in ~/.zshrc like that: export JVM_XMX=-Xmx2048M. I can verify that it was set correctly running export command and finding it in the list.
Now I want to use it in SBT. I've tried these two approaches:
sys.env("JVM_XMX")
sys.env.get("JVM_XMX")
But the value couldn't be found or the Option is None. Errors that I see are:
NoSuchElementException: key not found: JVM_XMX
NoSuchElementException: None.get
What I also tried was to add the variable into SBT in IntelliJ Settings. I went to Build, Execution, Deployment -> Build Tools -> sbt and set VM parameters to -DJVM_XMX=-Xmx2048M. It didn't help.
Anyone knows how to setup SBT to work with IntelliJ correctly?
Versions used:
sbt 1.2.8
IntelliJ IDEA 2019.2.1
As a workaround I was able to use system properties (scala.sys.SystemProperties). This works because this is the way how to find values added into SBT in IntelliJ Settings.
Code example from build.sbt:
sys.props.get("JVM_XMX")
UPDATE:
I was finally able to figure out what was the real problem. My .bashrc file was incorrectly set up (I had the variables only in .zshrc). After adding environment variables into correct rc file, the problem was fixed.
If you'd like this property to be part of your project, and not only in your solution, you can add a file names ".sbtopts" at the root of your repository, next to the build.sbt file.
In this file you can configure the JVM options.
For instance you can add there:
-J-Xmx2048M
I couldn't find the sbt documentation supporting my suggestion, but it works for me :)
I was able to work around this issue by going to Preferences -> Build, Execution, Deployment -> Build Tools -> sbt, then enabling sbt shell for builds and project reload.

Use custom script in Intelij IDEA to run sbt shell

Is it possible to run sbt shell in Intelij IDEA using custom script instead of built in sbt or sbt from sbt-launch.jar? Why I need this, for example there is some project which uses custom script to set config file location, VM parameters, and other options for sbt and this script is shared in version control system. And it would be very convenient to just specify for IntelliJ IDEA location of such script.
This is currently not possible. However, to pass project-specific sbt command line parameters to sbt you may place a .sbtopts in your project directory, and likewise a .jvmopts for VM parameters.

Intellij Command Used for "Refrsh SBT Project"

I'm wondering what is the actual sbt command that Intellij is executing when I use "Refresh sbt project" from the sbt window. I would like to understand how the same command can be issued from the sbt shell.
The IntelliJ Scala plugin ships with the sbt-structure sbt plugin, which gets automatically loaded with sbt shell sessions that you start from the IDE. When you enable sbt shell for imports, a refresh simply writes commands similar to these to the sbt shell:
> set org.jetbrains.sbt.StrcutureKeys.sbtStructureOptions in Global := "prettyPrint download"
> */*:dumpStructureTo structure.xml
To actually import the project structure, IntelliJ also runs an additional step which does not happen in sbt.