Skip to content
Horacio Sanson edited this page Dec 10, 2022 · 3 revisions

Linter installation guides

Checkstyle

The easiest way to install checkstyle so it is automatically detected by ALE is via package managers:

apt install checkstyle  # Ubuntu/Linux
brew install checkstyle # MacOS

You can also download the latest checkstyle-8.XX-all.jar file from the official download page and create a custom launch script like the one below to start checkstyle:

#!/bin/sh

java -jar checkstyle-8.XX-all.jar "@"

The advantages of using launch scripts is that you can use the latest version of checkstyle and add custom options to the command line:

#!/bin/sh

java -classpath MyCustom.jar;checkstyle-8.7-all.jar \
    com.puppycrawl.tools.checkstyle.Main "$@"

Once you create the launch script save it as checkstyle somewhere on your $PATH so ALE can find and use it. Also make sure to make the launch script executable:

chmod u+x checkstyle

Notes:

  1. Do not add the -c option to the launch script. This option will be added by ALE when invoking the command.

Java Language Server

To build the Java language server you need Java 11 and Maven. In Ubuntu 18.04 these can be installed with:

sudo apt-get install openjdk-11-jdk maven

Ensure you JAVA_HOME environment variable is correctly set. The absolute path may differ on your environment:

export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64

Clone and build the language server:

git clone https://github.com/georgewfraser/java-language-server.git
cd java-language-server
scripts/link_mac.sh

In Windows you must use the link_windows.sh script instead to build the language server. This generates a dist/mac or dist/windows directory that contains the language server.

Finally let ALE know where the language server executable is by setting the g:ale_java_javalsp_executable variable on your vim configuration:

let g:ale_java_javalsp_executable = <path-to-java-language-server>/java-language-server/dist/mac/bin/launcher

Gradle/Android

The Java language server will find most dependencies on maven/gradle projects but it may fail to find all of them. This is specially true for Android dependencies. In this case is possible to set external dependencies explicitly by setting the g:ale_java_javalsp_config dictionary:

let g:ale_java_javalsp_executable =
\ {
\   'java': {
\     'externalDependencies': [
\       'junit:junit:jar:4.12:test',   " Maven format
\       'junit:junit:4.1'              " Gradle format
\     ],
\     'classPath': [
\       'lib/some-dependency.jar',
\       '/android-sdk/platforms/android-28.jar'
\     ]
\   }
\ }

The Java language server will look for the dependencies you specify in externalDependencies array in your Maven and Gradle caches ~/.m2 and ~/.gradle.

Manually finding all dependencies and adding them to the dictionary is not efficient. Instead you can install the vim-android plugin. This plugin detects the presence of ALE and automatically fills the classPath with all dependencies for Gradle and Android projects.

Eclipse JDT

Download latest pre-build JDT from https://download.eclipse.org/jdtls/milestones/ and set set g:ale_java_eclipselsp_path to the path where you uncompressed it in your vim configuration:

let g:ale_java_eclipselsp_path = '/path/to/jdt-1.18.0'

Make sure to download Java 17 and set it as system default or set g:ale_java_eclipselsp_executable to the java 17 executable in your vim configuration. JDT 1.14.0 and newer won't work with older versions of java:

let g:ale_java_eclipselsp_executable = '/usr/lib/jvm/java-17-amazon-corretto/bin/java'

Also enable eclipselsp for java files in your vim configuration:

let g:ale_linters = {'java': ['eclipselsp']}

For auto-complete to work you must have enabled autoimport:

let g:ale_completion_autoimport = 1

Android Support

  1. Add vim-android to your vim plugins.
  2. Android requires Java 8 or 11 so make sure to make it your system default. In this case is important to set g:ale_java_eclipselsp_executable to java 17 binary. This would allow gradle (vim-android) to build android projects using the system java version (8 or 11) and JDT run using java 17.

Notes:

  1. Make sure you current directory is the root of the android project.
  2. Give it some time so vim-android builds the project and gets the dependencies.
  3. vim-android will generate a .classpath that includes android dependencies. This file is then used by eclipselsp to find them.
  4. Unfortunatelly there is no way for vim-android to notify JDT about changes to the dependencies. Therefore changes to gradle dependencies require a restart of JDT to take effect.