Skip to content

Java and Kotlin

Open a Maven or Gradle project and Ferris IDEA reads its modules and dependencies, starts jdtls for Java and kotlin-language-server for Kotlin, offers build, test and framework run configurations, and debugs on the JVM with hot swap for Java. Java and Kotlin support is Works.

  • A JDK. Ferris IDEA finds JDKs in JAVA_HOME, /Library/Java/JavaVirtualMachines and ~/Library/Java/JavaVirtualMachines (macOS), /usr/lib/jvm (Linux), ~/.jdks, SDKMAN, the JDKs Gradle provisioned, and the PATH. It reads the version the project asks for from pom.xml, the Gradle build, .java-version, .sdkmanrc or .idea/misc.xml.

  • Maven or Gradle, or the project’s wrapper (./mvnw, ./gradlew), which is used when present.

  • jdtls for Java. It needs the JDK it was built for. On Linux, use the distribution’s package or the Eclipse JDT Language Server download.

    macOS
    brew install jdtls

    The install hint Ferris IDEA names in language_servers, version 1.6.0.

  • kotlin-language-server for Kotlin:

    macOS
    brew install kotlin-language-server
  • java-debug for debugging Java: the plugin jar com.microsoft.java.debug.plugin-0.53.x.jar of the java-debug project in ~/.local/opt/java-debug, or its path in the environment variable FERRIS_IDEA_JAVA_DEBUG. Only the 0.53 series is accepted.

  • kotlin-debug-adapter for debugging Kotlin: unpack its release so that ~/.local/opt/kotlin-debug-adapter-<version>/adapter/bin/kotlin-debug-adapter exists, or put it on the PATH, or name it in FERRIS_IDEA_KOTLIN_DEBUG.

Settings › Build, Execution, Deployment › Build Tools shows which JDKs were found, which one fits the project and why, and whether Maven and Gradle come from the project’s wrapper, the PATH or are not installed. The page only reads.

Ferris IDEA reads pom.xml, build.gradle and build.gradle.kts, with their modules and dependencies. View › Tool Windows › Maven and Gradle show the modules, their tasks and the dependency tree. A project saved by IntelliJ IDEA (.idea or .ipr) also brings its modules, source roots, libraries and run configurations when you open it.

When the build file names Lombok, its jar from the local Maven or Gradle cache is passed to jdtls, so the generated getters and builders are known. In a project you have not trusted, Lombok is not loaded and kotlin-language-server is not started, because it runs the build.

  • Completion, smart completion, auto-import, parameter info, navigation, type and call hierarchy, find usages and inspections from the servers, plus Ferris IDEA’s own Java and Kotlin inspections (string or array compared with ==, ignored results, integer division, unused imports, locals, parameters and private members, empty catch, and others).
  • Code › Generate… (⌘N): for Java Constructor, Getter, Setter, Getter and Setter, equals() and hashCode(), toString(), Override, Implement and Delegate Methods, Test… and Copyright; for Kotlin Secondary Constructor, equals() and hashCode(), toString(), Override and Implement Members.
  • Code › Override Methods… (⌃O), Implement Methods… (⌃I), Delegate Methods… and Surround With… (⌥⌘T; Java only).
  • Code › Optimize Imports (⌃⌥O) for Java is Ferris IDEA’s own: it removes unused imports and sorts the rest, and never collapses imports into *.
  • Reformat Code (⌥⌘L) formats through the server. For Kotlin a selection is formatted as part of the whole file.
  • Refactor: rename, Extract Variable, Constant, Field, Parameter and Method, and Inline, including three variants of Inline Method, for Java. Kotlin has rename and the server’s code actions, but not Ferris IDEA’s own Extract and Surround With.
  • Spring, Jakarta EE, Quarkus and Micronaut: beans, configuration keys and HTTP endpoints are found in the code and listed in Search Everywhere’s Endpoints tab.

The run list shows under “Detected from build files”:

Build Configurations
Maven mvn compile, mvn test; Spring Boot, Quarkus dev or Micronaut run when the project uses that framework
Gradle gradle build, gradle test; bootRun, quarkusDev or run for the frameworks

Test configurations read the JUnit reports (target/surefire-reports, build/test-results/test) into the result tree; see Run tests.

Run › Run Current File (⌃⇧R):

Caret in Command
a Java class with main, Maven mvn -q compile exec:java -Dexec.mainClass=…
a Java class with main, no build tool javac, then java -cp …, or java File.java for a single file
a test class or method, Maven mvn test -Dtest=Class#method
a test class or method, Gradle gradle test --tests pkg.Class.method
a Kotlin main, Gradle gradle -q classes, then kotlin -cp build/classes/kotlin/main MainKt
a Kotlin main, Maven mvn -q compile, then kotlin -cp target/classes …
a Kotlin main, no build tool kotlinc … -include-runtime -d .ferris-idea/run/<name>.jar, then java -jar
  1. Set a breakpoint (⌘F8). On a Java method header it becomes a method breakpoint, drawn as a diamond.
  2. Run › Debug Current File (⌃⇧D) on a class with main. Java runs under java-debug inside jdtls; Kotlin under kotlin-debug-adapter.
  3. Java gets the full set: exception breakpoints by class, field watchpoints, thread selection with states and groups, and hot swap. kotlin-debug-adapter does not evaluate conditions, hit counts and log messages itself, so Ferris IDEA evaluates them at each stop, which is slower; the debug console says so.

Hot swap (Java): save a changed Java file while the session runs. A bar shows “Code changed” with Reload Changed Classes (⌃⌥⇧F9). Details and limits: Attach and hot swap.

To debug a JVM that is already running with a JDWP port, use Attach to Process with host:port.

  • jdtls starts but finds nothing: it needs the JDK it was built for; check Settings › Build, Execution, Deployment › Build Tools and JAVA_HOME.
  • “Cannot debug Java: the java-debug plugin is not installed …”: put the 0.53 jar into ~/.local/opt/java-debug.
  • “Cannot debug Kotlin: kotlin-debug-adapter is missing …”: unpack its release into ~/.local/opt or set FERRIS_IDEA_KOTLIN_DEBUG.
  • Kotlin has no code insight in a new project: kotlin-language-server is not started in safe mode; trust the project.
Keyboard of
ActionShortcut
Code › Generate⌘N or ⌃↩AltInsert
Code › Implement Methods⌃ICtrlI
Code › Optimize Imports⌃⌥OCtrlAltO
Code › Override Methods⌃OCtrlO
Code › Surround With⌥⌘TCtrlAltT
HotswapHotswap⌃⌥⇧F9CtrlAltShiftF9
Navigate › Type Hierarchy⌃HCtrlH

  • build_projectchangesdry run by defaultruntrusted-projectBuild Project in one call: the window's Build Project chain (Before Build tasks, cargo, Maven, Gradle and Go builds, After Build tasks), stopping at the first failure.
  • debug_hot_swapchangesdebugHot swap (Reload Changed Classes, SPEC-0091 v12): builds the changed workspace sources files for a Java debug session (java-debug in jdtls) and reloads the changed classes into the running program; returns their names.
  • dependency_treechangesruntrusted-projectDependency tree and tasks of one module, as the build tools window shows them: transitive dependencies from Cargo.lock or package-lock.json (each package expanded once, later occurrences marked repeated); for Maven and Gradle from the build tool's resolution (Gradle per classpath configuration, a → b where Gradle chose another version), kept until the build file changes, made now with resolve=true (needs the run right) — resolved says whether the tree is current; direct dependencies with locked versions otherwise; tasks with their commands.
  • generate_choicesreadsWhat Generate offers in the Java class around a 1-based line: for each kind that applies its fields with checked (the default selection) and its templates, usable as fields and template of generate_code.
  • generate_codechangesdry run by defaultwriteGenerate code in the Java class around a line from its non-static fields, like the Generate menu: constructor, getters, setters, getters_and_setters, equals_hash_code or to_string; Java template picks one of generate_choices.
  • java_environmentreadsJava setup of the workspace without starting a JVM: installed JDKs (JAVA_HOME, system and user JVM folders, SDKMAN, Gradle JDKs, PATH) with version, feature release, vendor, compiler and architecture from their release files; the Java version the project states (Maven, Gradle toolchain/compatibility, .java-version, .sdkmanrc, .idea/misc.xml) with contradictions as problems; which JDK is selected and why, and whether it can build the project.
  • optimize_importschangesdry run by defaultwritetrusted-projectOptimize Imports.
  • override_methodschangesdry run by defaultwriteOverride/Implement Methods for the Java (via jdtls) or Kotlin class at a position.
  • project_modelreadsProject model read from the build files in the workspace (Cargo, npm, Python, Maven, Go; Gradle detected): modules with name, version, folder, toolchain, dependencies with scope, tasks and members; problems per build file; suggested run configurations (Python ones with the workspace's selected interpreter, ${workspace}/… inside the workspace).