- Notifications
You must be signed in to change notification settings - Fork1.5k
The easiest way to install checkstyle so it is automatically detected by ALE is via package managers:
apt install checkstyle # Ubuntu/Linuxbrew install checkstyle # MacOSYou can also download the latest checkstyle-8.XX-all.jar file from theofficial download page and create a custom launch script like the one below to start checkstyle:
#!/bin/shjava -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 thecommand line:
#!/bin/shjava -classpath MyCustom.jar;checkstyle-8.7-all.jar \ com.puppycrawl.tools.checkstyle.Main"$@"
Once you create the launch script save it ascheckstyle somewhere on your $PATH so ALE can find and use it. Also make sure to make the launch script executable:
chmod u+x checkstyleNotes:
- Do not add the
-coption 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 mavenEnsure 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-amd64Clone and build the language server:
git clone https://github.com/georgewfraser/java-language-server.gitcd java-language-serverscripts/link_mac.shIn Windows you must use thelink_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 theg: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/launcherThe 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 theg: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 inexternalDependencies 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 thevim-android plugin. This plugin detects the presence of ALE and automatically fills the classPath with all dependencies for Gradle and Android projects.
Download latest pre-build JDT fromhttps://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 setg: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 enableeclipselsp 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- Addvim-android to your vim plugins.
- Android requires Java8 or11 so make sure to make it your system default. In this case is important to set
g:ale_java_eclipselsp_executableto 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:
- Make sure you current directory is the root of the android project.
- Give it some time so vim-android builds the project and gets the dependencies.
- vim-android will generate a .classpath that includes android dependencies. This file is then used by eclipselsp to find them.
- 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.