Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save therealcisse/5f408833c469fc29a1f244c0e8770717 to your computer and use it in GitHub Desktop.
Save therealcisse/5f408833c469fc29a1f244c0e8770717 to your computer and use it in GitHub Desktop.
SBT and JVM Debugging tricks

IntelliJ and recursive data structures

You may need to override toString on any recursive or deeply-nested data structure, since IntelliJ will ask the Java Debugger (JDB) to call toString all the time. This will blow up your memory.

Remote debugging

Useful for any number of reasons: testing on a different OS, using lots of memory/cpu resources you don't have locally, etc.

See an Intellij / IDEA guide for background.

Edit remote build.sbt to include no forking in Test, e.g.:

  settings(
    fork in Test := false,
	//...

Then you can run from the command line:

JAVA_OPTS="-Xms2G -Xmx180G -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8600" sbt

Disabling network connections

Linux

If you don't use Linux locally, see above for remote debugging guide. Note that due to a partially broken feature in SBT, YMMV with this method. You will need sudo privileges on the Linux system to use this method, though there are workarounds and alternatives like lxc-usernsexec.

Start up a shell without network access (all children will inherit the same lack of network access):

sudo unshare -n su - <myUserName>

You can verify networking is not working:

sbt "set offline := true" 'eval "ping 127.0.0.1" !'

Run your desired test in SBT with offline mode enabled:

JAVA_OPTS="-Xms2G -Xmx180G" sbt "set offline := true" 'testOnly edu.ncrn.cornell.xml.DdiCodebookSpec'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment