How to debug tests ran from sbt - sbt

Tests run from sbt don't show an stacktrace when an exception happens, so I would like to connect to sbt from a debugger to debug the tests. What is an easy way of doing that?

Using the sbt deb/rpm provided by typesafe, this works:
sbt -jvm-debug 8000

You can create a separate sbt launcher with the java jdwp args, i.e.
-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address=10000
From here, you can connect your debugger to port 10,000.

Related

Unable to run corda tests from IntelliJ

When I select and run a test, the build fails with the message:
"Kotlin: Usage of '#JvmDefault' is only allowed if the flag -Xenable-jvm-default is enabled" for the following files.
corda/serialization/src/main/kotlin/net/corda/serialization/internal/OrdinalIO.kt
corda/serialization/src/main/kotlin/net/corda/serialization/internal/SerializationFormat.kt
corda/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/AMQPSerializer.kt
I have cloned corda from my fork of corda/corda on github, and am on branch master, opened in IntelliJ as per instructions on the docsite. The JDK version is 1.8.0_152 and the Kotlin plugin is on version 1.2.41. I see that the -Xenable-jvm-default is enabled in the corda/build.gradle file. There are no local changes. Could you please advise on what I missed or need to do to fix this?
This can be fixed by invalidating IntelliJ's caches and restarting IntelliJ. See jetbrains.com/help/rider/Cleaning_System_Cache.html.
Make sure you are using the gradle runner to execute the tests on IntelliJ.
Navigate to Build, Execution, Deployment -> Build Tools -> Gradle -> Runner (or search for runner)
Windows: this is in “Settings”
MacOS: this is in “Preferences”
Set “Delegate IDE build/run actions to gradle” to true
Set “Run test using:” to “Gradle Test Runner”

Run SBT without installing it first

I was wondering if SBT has something similar to the Gradle Wrapper?
I would like to use it on a CI server without having to install SBT first.
The documentation mentions a sbt-launcher, but that seems to be geared towards running actual application instead of builds.
Yes, sbt-extras is a bash script that you can commit to your repository to act like the gradle wrapper.
The sbt-extras project is centered around a stand-alone script called sbt which can be directly used to run sbt without having it on the machine first.
The script has logic to determine the proper version of sbt for the project, download the correct version of the sbt jar, and then run the tasks through sbt.
If you copy the sbt script into your project, you can simply call it — from your CI server, locally, or wherever — to run sbt tasks without needing sbt installed separately.

sbt hanging on process which runs on another computer

sbt works fine for one project on this computer but does not even load up (sbt console never returns). Sbt command works for both projects on another computer. I have tried running sbt clean but I get the same result. Are there any steps I can take to troublehssot, gather more information and run the sbt console correctly? Sbt version is 0.13.9
I was able to run sbt after removing Build.scala and plugins.sbt file which were not needed for the project (perhaps I am mistaken in that assumption). For some reason, without removing the files, the sbt console was not coming up (or was going to take a very long time before coming up).

When your build failed in automated process

I have a script that does the 'build' in several servers once I run it. I am now trying to figure out how to know if build failed. For example, the script will run the 3 commands(shown below), how would I know if my pre-build failed?
During the build process I have to run the following commands:
./ant pre-build
./ant install1
./ant post-build
I can use ssh, puppet etc. in my Redhat machine, and don't have anything more than that. Is there an application or a management tool that will let me monitor my build process in UI?
You can check the return code of the ant executable as mentioned in the Running Apache Ant:
the ant start up scripts (in their Windows and Unix version) return the return code of the java program. So a successful build returns 0, failed builds return other values.

SBT Plugin to modify compile and test tasks

I am in the process of creating a plugin that will modify both the compile:compile and test:test tasks. My ultimate aim is to be able to do sbt monkjack or sbt monkjack:test (either is fine). In the compile:compile scope I need to add a compiler plugin, and in the test:test scope I need to run some code after the tests have finished.
My first attempts were around trying to create a custom configuration but which to extend, compile or test, was unclear as both are needed (At the moment I have two, and I copy the CustomTest into the CustomCompile and then run monkjack:test). My second attempts were focusing on a custom task that in turn invoked (compile in Compile).value and (test in Test).value after setting various options.
I realize my knowledge of SBT tasks and how they are related/inherited/scoped is not great.
Q1. Is there a chain of tasks like in maven? In maven if you execute test, it will execute the other phases in order. So mvn clean test will automatically run prepare-sources, compile, etc etc. So in SBT if I run sbt test how are the other tasks automatically executed.
Q2. If you execute a task with a custom config, eg sbt millertime:test will that config propagate to the other tasks that run. Eg, is this the same as sbt monkjack:compile monkjack:test or the same as sbt compile monkjack:test or neither :)
Q3. How do tasks know which is their default config? If I do sbt compile how does SBT know that means sbt compile:compile?
Q4. Which is the best way to go here, a custom configuration or a new task.

Resources