dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.57k stars 1.44k forks source link

Javac Linter Not Picking up on Spring Imports or Annotations #1280

Open JustinHoyt opened 6 years ago

JustinHoyt commented 6 years ago

Information

VIM version VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 27 2017 10:05:25) macOS version

Operating System MacOS High Sierra

:ALEInfo

Current Filetype: Available Linters: [] Enabled Linters: [] Linter Variables: Global Variables: let g:ale_echo_cursor = 1 let g:ale_echo_msg_error_str = 'Error' let g:ale_echo_msg_format = '%code: %%s' let g:ale_echo_msg_warning_str = 'Warning' let g:ale_enabled = 1 let g:ale_fix_on_save = 1 let g:ale_fixers = {'javascript': ['eslint'], 'python': ['autopep8']} let g:ale_keep_list_window_open = 0 let g:ale_lint_delay = 200 let g:ale_lint_on_enter = 1 let g:ale_lint_on_save = 1 let g:ale_lint_on_text_changed = 'always' let g:ale_linter_aliases = {} let g:ale_linters = {'java': ['javac'], 'python': ['mypy']} let g:ale_open_list = 0 let g:ale_set_highlights = 1 let g:ale_set_loclist = 1 let g:ale_set_quickfix = 0 let g:ale_set_signs = 1 let g:ale_sign_column_always = 0 let g:ale_sign_error = '>>' let g:ale_sign_offset = 1000000 let g:ale_sign_warning = '--' let g:ale_statusline_format = ['%d error(s)', '%d warning(s)', 'OK'] let g:ale_warn_about_trailing_whitespace = 1 Command History:

What went wrong

ALE with javac picks up all imports and annotations except for things relating to the Spring framework. For example:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

these imports result in the error "error: package org.springframework.XXX.YYY does not exist"

An example of the spring annotations not working are:

@Component

This results in the error: "error: cannot find symbol: Component"

Reproducing the bug

Steps for repeating the bug:

  1. Turn on javac linting
  2. Open any Gradle Spring boot project to a file that has Spring imports and/or annotations
laran commented 2 years ago

I have this issue also

hsanson commented 1 year ago

I do not use javac linter but from what I can see ALE uses this command to figure out the Classpath to use when linting:

 ./gradlew -I /path/to/ale/autoload/ale/gradle/init.gradle -q printClasspath

This command varies depending on each environment. For example the "init.gradle" file is inside the ALE autoload folder and the executable "./gradlew" can be "gradle" if the wrapper is not available.

I would first try to see if gradle itself is returning the necessary spring dependencies as part of this command and if not figure out how to make it include them so ALE can pick them up.

Hritik14 commented 1 year ago

@hsanson I'm facing a similar problem. I was able to get classpath from gradle using the above command although ale is running the following command (mentioned in :ALEInfo)

(finished - exit code 1) ['/bin/zsh', '-c', 'cd ''/path/to/project/src/main/java/name/of/package/controller'' && ''javac'' -Xli
nt -sourcepath ''/path/to/project/src/main/java/'' -d ''/var/folders/l1/tbpy9vkn2151gnkf324c1bdm0000gr/T/v2gIneV/3'' ''/var/folders/l
1/tbpy9vkn2151gnkf324c1bdm0000gr/T/v2gIneV/4/BaseController.java''']
hsanson commented 1 year ago

Very difficult to know without having a test project that presents the problem. I downloaded a Spring hello world project from github and configured only javac linter:

ALE runs the command with all the dependencies found and seems to work fine on my test:

 <<<OUTPUT ENDS>>>
(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/home/ryujin/Projects/HelloWorld/spring-helloworld/src/main/java/net/paulcz/hello'' && ''javac'' -Xlint -cp ''/home/ry
ujin/.m2/repository/org/springframework/boot/spring-boot-starter/2.1.3.RELEASE/spring-boot-starter-2.1.3.RELEASE.jar:/home/ryujin/.m2/repository/org/springframework/boot
/spring-boot/2.1.3.RELEASE/spring-boot-2.1.3.RELEASE.jar:/home/ryujin/.m2/repository/org/springframework/spring-context/5.1.5.RELEASE/spring-context-5.1.5.RELEASE.jar:/h
ome/ryujin/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.1.3.RELEASE/spring-boot-autoconfigure-2.1.3.RELEASE.jar:/home/ryujin/.m2/repository/org/sp
ringframework/boot/spring-boot-starter-logging/2.1.3.RELEASE/spring-boot-starter-logging-2.1.3.RELEASE.jar:/home/ryujin/.m2/repository/ch/qos/logback/logback-classic/1.2
.3/logback-classic-1.2.3.jar:/home/ryujin/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:/home/ryujin/.m2/repository/org/slf4j/slf4j-api/1.7.25/
slf4j-api-1.7.25.jar:/home/ryujin/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.11.2/log4j-to-slf4j-2.11.2.jar:/home/ryujin/.m2/repository/org/apache/logging/
log4j/log4j-api/2.11.2/log4j-api-2.11.2.jar:/home/ryujin/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar:/home/ryujin/.m2/repository/javax/annotatio
n/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar:/home/ryujin/.m2/repository/org/springframework/spring-core/5.1.5.RELEASE/spring-core-5.1.5.RELEASE.jar:/home
/ryujin/.m2/repository/org/springframework/spring-jcl/5.1.5.RELEASE/spring-jcl-5.1.5.RELEASE.jar:/home/ryujin/.m2/repository/org/yaml/snakeyaml/1.23/snakeyaml-1.23.jar:/
home/ryujin/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.1.3.RELEASE/spring-boot-starter-web-2.1.3.RELEASE.jar:/home/ryujin/.m2/repository/org/sprin
gframework/boot/spring-boot-starter-json/2.1.3.RELEASE/spring-boot-starter-json-2.1.3.RELEASE.jar:/home/ryujin/.m2/repository/com/fasterxml/jackson/core/jackson-databind
/2.9.8/jackson-databind-2.9.8.jar:/home/ryujin/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar:/home/ryujin/.m2/reposit
ory/com/fasterxml/jackson/core/jackson-core/2.9.8/jackson-core-2.9.8.jar:/home/ryujin/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.9.8/jackson-d
atatype-jdk8-2.9.8.jar:/home/ryujin/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.9.8/jackson-datatype-jsr310-2.9.8.jar:/home/ryujin/.m2/reposi
tory/com/fasterxml/jackson/module/jackson-module-parameter-names/2.9.8/jackson-module-parameter-names-2.9.8.jar:/home/ryujin/.m2/repository/org/springframework/boot/spri
ng-boot-starter-tomcat/2.1.3.RELEASE/spring-boot-starter-tomcat-2.1.3.RELEASE.jar:/home/ryujin/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.16/tomcat-emb
ed-core-9.0.16.jar:/home/ryujin/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/9.0.16/tomcat-embed-el-9.0.16.jar:/home/ryujin/.m2/repository/org/apache/tomcat/em
bed/tomcat-embed-websocket/9.0.16/tomcat-embed-websocket-9.0.16.jar:/home/ryujin/.m2/repository/org/hibernate/validator/hibernate-validator/6.0.14.Final/hibernate-valida
tor-6.0.14.Final.jar:/home/ryujin/.m2/repository/javax/validation/validation-api/2.0.1.Final/validation-api-2.0.1.Final.jar:/home/ryujin/.m2/repository/org/jboss/logging
/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final.jar:/home/ryujin/.m2/repository/com/fasterxml/classmate/1.4.0/classmate-1.4.0.jar:/home/ryujin/.m2/repository/org/sp
ringframework/spring-web/5.1.5.RELEASE/spring-web-5.1.5.RELEASE.jar:/home/ryujin/.m2/repository/org/springframework/spring-beans/5.1.5.RELEASE/spring-beans-5.1.5.RELEASE
.jar:/home/ryujin/.m2/repository/org/springframework/spring-webmvc/5.1.5.RELEASE/spring-webmvc-5.1.5.RELEASE.jar:/home/ryujin/.m2/repository/org/springframework/spring-a
op/5.1.5.RELEASE/spring-aop-5.1.5.RELEASE.jar:/home/ryujin/.m2/repository/org/springframework/spring-expression/5.1.5.RELEASE/spring-expression-5.1.5.RELEASE.jar:/home/r
yujin/.m2/repository/org/springframework/boot/spring-boot-starter-actuator/2.1.3.RELEASE/spring-boot-starter-actuator-2.1.3.RELEASE.jar:/home/ryujin/.m2/repository/org/s
pringframework/boot/spring-boot-actuator-autoconfigure/2.1.3.RELEASE/spring-boot-actuator-autoconfigure-2.1.3.RELEASE.jar:/home/ryujin/.m2/repository/org/springframework
/boot/spring-boot-actuator/2.1.3.RELEASE/spring-boot-actuator-2.1.3.RELEASE.jar:/home/ryujin/.m2/repository/io/micrometer/micrometer-core/1.1.3/micrometer-core-1.1.3.jar
:/home/ryujin/.m2/repository/org/hdrhistogram/HdrHistogram/2.1.9/HdrHistogram-2.1.9.jar:/home/ryujin/.m2/repository/org/latencyutils/LatencyUtils/2.0.3/LatencyUtils-2.0.
3.jar:/home/ryujin/.m2/repository/org/springframework/cloud/spring-cloud-starter-kubernetes-config/1.0.0.RELEASE/spring-cloud-starter-kubernetes-config-1.0.0.RELEASE.jar
:/home/ryujin/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-core/1.0.0.RELEASE/spring-cloud-kubernetes-core-1.0.0.RELEASE.jar:/home/ryujin/.m2/reposit
ory/io/fabric8/kubernetes-client/4.1.0/kubernetes-client-4.1.0.jar:/home/ryujin/.m2/repository/io/fabric8/kubernetes-model/4.1.0/kubernetes-model-4.1.0.jar:/home/ryujin/
.m2/repository/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.9.8/jackson-module-jaxb-annotations-2.9.8.jar:/home/ryujin/.m2/repository/com/squareup/okht
tp3/okhttp/3.8.1/okhttp-3.8.1.jar:/home/ryujin/.m2/repository/com/squareup/okio/okio/1.13.0/okio-1.13.0.jar:/home/ryujin/.m2/repository/com/squareup/okhttp3/logging-inte
rceptor/3.8.1/logging-interceptor-3.8.1.jar:/home/ryujin/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.9.8/jackson-dataformat-yaml-2.9.8.jar:
/home/ryujin/.m2/repository/io/fabric8/zjsonpatch/0.3.0/zjsonpatch-0.3.0.jar:/home/ryujin/.m2/repository/com/github/mifmif/generex/1.0.1/generex-1.0.1.jar:/home/ryujin/.
m2/repository/dk/brics/automaton/automaton/1.11-8/automaton-1.11-8.jar:/home/ryujin/.m2/repository/org/springframework/cloud/spring-cloud-context/2.1.0.RELEASE/spring-cl
oud-context-2.1.0.RELEASE.jar:/home/ryujin/.m2/repository/org/springframework/security/spring-security-crypto/5.1.4.RELEASE/spring-security-crypto-5.1.4.RELEASE.jar:/hom
e/ryujin/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-config/1.0.0.RELEASE/spring-cloud-kubernetes-config-1.0.0.RELEASE.jar:/home/ryujin/.m2/reposito
ry/org/springframework/security/spring-security-rsa/1.0.7.RELEASE/spring-security-rsa-1.0.7.RELEASE.jar:/home/ryujin/.m2/repository/org/bouncycastle/bcpkix-jdk15on/1.60/
bcpkix-jdk15on-1.60.jar:/home/ryujin/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.60/bcprov-jdk15on-1.60.jar'' -sourcepath ''/home/ryujin/Projects/HelloWorld/spring-
helloworld/src/main/java/'' -d ''/tmp/nvim.ryujin/yGNlxK/1'' ''/tmp/nvim.ryujin/yGNlxK/2/Application.java''']
<<<NO OUTPUT RETURNED>>>

I must mention I do not use javac linter nor work with Spring. I do mostly Android using eclipselsp for Java and KotlinLanguageServer for Kotlin.

Hritik14 commented 1 year ago

@hsanson I was able to reproduce the issue with the same test project. In order for ALE to consider gradle, you'll need to remove the mvn files rm mvnw mvnw.cmd pom.xml