-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Java
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:
- Do not add the
-c
option to the launch script. This option will be added by ALE when invoking the command.
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
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.