A minimal Maven project to help with SNT/Fiji Groovy scripting.
Fiji's Script Editor is functional but has no real autocompletion for Groovy. IDEs on the other hand, offer autocomplete, jump-to-source, and inline SNT/ImageJ Javadoc, which makes writing anything beyond a trivial script much easier.
This project (inspired by QuPath's gradle-scripting-project) sets this up automatically: It solves the tricky part of getting the IDE to see SNT and all of Fiji's other libraries.
- Download or clone this repo
- In IntelliJ (ultimate subscription is NOT needed): File -> Open... and select this
folder: IntelliJ will detect the
pom.xmland import it as a Maven project automatically - Let it finish indexing (first import downloads SNT + dependencies; note it can take several minutes)
- IntelliJ should also pop up a notification that it found
snt-scijava-params.gdsl- accept/enable it (or go to Settings -> Languages & Frameworks -> Groovy -> Groovy DSL Awareness). This teaches IntelliJ about Scijava @ parameters. It won't clear the squiggles on the#@...header lines themselves (see note below) - Write scripts as
.groovyfiles insidescripts/ - Enjoy real autocompletion, navigation, and inline docs against SNT/ImageJ
- Whenever you want to actually run a script, open it in Fiji's own Script Editor (or drag the file onto Fiji's main window). This project is for editing scripts. It does not run them standalone.
Integration with VS Code is more fragile than the IntelliJ route, but still possible:
- Run
mvn dependency:resolveonce in this folder so all jars are cached to~/.m2/repository - Install a Groovy language server build and a generic LSP-client extension (e.g.
glspc) - Point
groovy.classpathin VS Code settings at the resolved jars, e.g. the output ofmvn dependency:build-classpath -Dmdep.outputFile=cp.txt
scripts/ ships four files:
hello.groovy: sanity check that the everything is properly setup01_precursor_autotrace.groovy: auto-traces the ddaC demo image02_curation_quality_report.groovy: runs plausibility/crossover checks03_quantification_sholl.groovy: linear + angular Sholl profiles
Each has a // TODO (exercise) marking where to adapt it to your own data
Note on the
#@header linesLines like
#@SNTService sntare SciJava's parameter-injection syntax. Fiji's Script Editor strips and interprets them before compiling the rest of the script - that's howsnt,ui, etc. get bound automatically. Plain IDEs don't know this convention, so IntelliJ/VS Code may underline those lines as a syntax error. That's cosmetic: the scripts still run correctly when opened in Fiji's own Script Editor, which is where you actually run them
snt-scijava-params.gdsl (see above) is what gives snt, ui, context,
etc. real types. If IntelliJ never picks it up (no per-file GDSL settings
page exists in recent IntelliJ versions, and the one-time "trust this
script" notification is easy to miss/dismiss with no obvious way back), it's
not worth losing time over: everything else still autocompletes normally,
since actual SNT/ImageJ classes resolve straight from the Maven dependency.
The only casualty is the handful of injected names themselves showing as "unresolved symbols". A one-line workaround, whenever you want autocomplete past one of them, is an inline cast:
((SNTService) snt).getPathAndFillManager() // autocompletes after the cast
((UIService) ui).showDialog("done")This doesn't change runtime behavior (Fiji still injects the real object; the cast is a no-op at runtime beyond a type-check) - it's purely to give IntelliJ enough information to suggest members past that point.
Bump <snt.version> in pom.xml to match whatever SNT release (or
-SNAPSHOT) you're targeting, then re-import the Maven project (IntelliJ:
the little Maven refresh icon, or Reload All Maven Projects).
Just a template, use as you wish, no warranty.