mopemope / meghanada-emacs

A Better Java Development Environment for Emacs
GNU General Public License v3.0
603 stars 56 forks source link

Error compiling file with junit dependency in gradle project #183

Open efim opened 2 years ago

efim commented 2 years ago

Hello!

I'm trying out java coding after very long period of not using it, currently trying to figure out gradle basics, while working in Emacs Doom.

I've set up basic gradle hello-world project, with jdk11 and gradle 7.5 in direnv gradle build from the terminal all seems to compile and produce test results

I installed meghanada module for Doom Emacs and some things seem to work: the server download process was completed, and server seem to start if I try to execute M-x meghanada-run-task build - i get successful output in a *meghanada-task* buffer

Hovewer the the test file shows errors around @Test annotation and junit import, and *meghanada-server-log* shows that junit is not found as a project dependency

WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
[INFO ][Main      :  54] use java home: /nix/store/jls0ax3l7vca6vkgwfah1fxcpdibclrx-openjdk-11.0.15+10/lib/openjdk
[INFO ][Main      :  55] use java runtime: OpenJDK Runtime Environment 11.0.15+0-adhoc..source
[INFO ][Main      :  59] use java vm: OpenJDK 64-Bit Server VM 11.0.15+0-adhoc..source
[INFO ][Main      : 151] Meghanada-Server Version:1.3.2-release
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.nustaq.serialization.FSTClazzInfo (file:/home/efim/.emacs.d/.local/etc/meghanada-server/meghanada-1.3.2.jar) to field java.lang.String.value
WARNING: Please consider reporting this to the maintainers of org.nustaq.serialization.FSTClazzInfo
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO ][Session   : 202] load project from cache. projectRoot:/home/efim/Documents/personal/java/gradle-study
[INFO ][EmacsServe: 366] zpage tracez handler http://localhost:41319/tracez
[INFO ][EmacsServe: 372] Start server Listen localhost port:38045
[INFO ][EmacsServe: 394] client connected
[INFO ][CacheEvent:  65] create class index ... read 0 jars. elapsed:2.226 s
[INFO ][CacheEvent:  71] start analyze sources ...
[INFO ][Project   : 339] project gradle-study compile and analyze (java) 0 files. force:false problem:0 elapsed:104.6 ms
[INFO ][Project   : 404] project gradle-study compile and analyze (test) 1 files. force:false problem:3 elapsed:6.024 s
[WARN ][CompileRes: 114] warning: No processor claimed any of these annotations: Test
[ERROR][CompileRes: 112] /home/efim/Documents/personal/java/gradle-study/src/test/java/com/study/GradleTutorialTest.java:3: error: package org.junit does not exist
import org.junit.Test;
                ^
[ERROR][CompileRes: 112] /home/efim/Documents/personal/java/gradle-study/src/test/java/com/study/GradleTutorialTest.java:7: error: cannot find symbol
    @Test
     ^
  symbol:   class Test
  location: class com.study.GradleTutorialTest
[INFO ][Config    : 139] analyzed and compiled. elapsed:6.176 s
[INFO ][CacheEvent:  88] class index size:7665 total elapsed:8.443 s
[INFO ][Config    : 202] memory usage (used/total/max): 170.00MB / 400.00MB / 7972.00MB
[INFO ][CacheEvent:  94] Ready
[INFO ][EmacsServe: 394] client connected
[INFO ][EmacsServe: 354] receive [rt, build]. 17.52 s

It seems that something other than gradle is being used for commands like meghanada-compile-*

Maybe I don't understand how to register project as a gradle project with meghanada, maybe having build.gradle is not enough and there has to be .project file (I found some references to that in the issues here, but couldn't find much about it online, I'm creating project structure manually and with gradle init)

My build.gradle file lists dependencies:

dependencies {
    testImplementation group: 'junit', name: 'junit', version: '4.13.2'
}

but M-x meghanada-show-project seems to show empty dependencies?

Project:
--------------------------------------------------------------------------------
project: gradle
projectRoot: /home/efim/Documents/personal/java/gradle-study
gradlePrepareCompileTask: []
gradlePrepareTestCompileTask: []
projectDatbase: /home/efim/.cache/meghanada/gradle-study_f8045940d9f298b6_b6cd32b9b133ceab
projectDatabaseSize:   5.00MB
source-formatter: google 
sources:
  /home/efim/Documents/personal/java/gradle-study/src/main/java
resources:
output:
  /home/efim/Documents/personal/java/gradle-study/build/classes/java/main
testSources:
  /home/efim/Documents/personal/java/gradle-study/src/test/java
testResources:
testOutput:
  /home/efim/Documents/personal/java/gradle-study/build/classes/java/test
dependencies:

Here is the full output of M-x meghanada-show-project is that's helpful: https://0x0.st/o3y8.txt