scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.04k stars 318 forks source link

Unable to import gradle build. #4036

Open ckipp01 opened 2 years ago

ckipp01 commented 2 years ago

Describe the bug

I don't have a clear reproduction yet, but just carrying this over from #vim-users on Discord where a person was setting this, but it didn't seem to be taking affect. I've never actually tested this out as I never use gradle, but it seemed to not be working in their example. This needs to be checked.

Expected behavior

No response

Operating system

macOS

Version of Metals

latest

Commit of nvim-metals

latest

fiatjaf commented 2 years ago

It's not working for me either.

I've tried setting gradleScript = vim.fn.getcwd() .. "/gradlew" and also gradleScript = "/home/fiatjaf/comp/sbw/gradlew", but the result is the same:

2022.06.14 19:38:52 INFO  Started Metals http server at http://127.0.0.1:5031
2022.06.14 19:38:54 INFO  no build target found for /home/fiatjaf/comp/sbw/app/src/main/scala/fiatjaf/wallet/sheets/ScannerBottomSheet.scala. Using presentation compiler with project's scala-library version: 3.1.1
2022.06.14 19:38:55 INFO  running '/tmp/metals17102824663325212014/gradlew --console=plain --init-script /tmp/metals17102824663325212014/init-script.gradle bloopInstall'
2022.06.14 19:38:56 ERROR
2022.06.14 19:38:56 ERROR FAILURE: Build failed with an exception.
2022.06.14 19:38:56 ERROR
2022.06.14 19:38:56 ERROR * Where:
2022.06.14 19:38:56 ERROR Build file '/home/fiatjaf/comp/sbw/app/build.gradle' line: 1
2022.06.14 19:38:56 ERROR
2022.06.14 19:38:56 ERROR * What went wrong:
2022.06.14 19:38:56 ERROR A problem occurred evaluating project ':app'.
2022.06.14 19:38:56 ERROR > Failed to apply plugin [id 'com.android.internal.version-check']
2022.06.14 19:38:56 ERROR    > Minimum supported Gradle version is 6.1.1. Current version is 5.3.1. If using the gradle wrapper, try editing the distributionUrl in /home/fiatjaf/.gradle/daemon/5.3.1/gradle/wrapper/gradle-wrapper.properties to gradle-6.1.1-all.zip
2022.06.14 19:38:56 ERROR
2022.06.14 19:38:56 ERROR * Try:
2022.06.14 19:38:56 ERROR Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
2022.06.14 19:38:56 ERROR
2022.06.14 19:38:56 ERROR * Get more help at https://help.gradle.org
2022.06.14 19:38:56 ERROR
2022.06.14 19:38:56 ERROR BUILD FAILED in 1s
2022.06.14 19:38:56 INFO  time: ran 'gradle bloopInstall' in 1.29s
2022.06.14 19:38:56 ERROR Gradle command failed: /tmp/metals17102824663325212014/gradlew --console=plain --init-script /tmp/metals17102824663325212014/init-script.gradle bloopInstall
2022.06.14 19:39:03 INFO  shutting down Metals

Another thing that is not working is the build target detection, which is likely due to the fact that this is an android project that has a build.gradle file and then another build.gradle file inside an app/ directory (I don't know why, but android projects normally are like this), right?

And the fallbackScalaVersion = "2.13.8" seeting I have also seems to be ignored.

When I open nvim on this project I get prompted by metals to select between gradle and sbt, even thought there are no sbt files in this repo anywhere.

What I did: I've followed the https://scalameta.org/metals/docs/build-tools/gradle/#manual-installation steps and added these plugins to gradle.

Another information that confuses me: if I start nvim at the root directory (/home/fiatjaf/comp/sbw/) I get metals prompts and it tries to install bloop etc (but fails, tells me to look at the logs), but I don't get a .metals directory and there are no logs -- but if I start nvim at the app/ subdirectory then I get the log files and errors above.

ckipp01 commented 2 years ago

Thanks for the extra info @fiatjaf. I'll need to dig in a bit further, but upon first try I just open a random scala file in the build and the following happened:

When I open nvim on this project I get prompted by metals to select between gradle and sbt, even thought there are no sbt files in this repo anywhere.

Make sure to double-check your workspace to ensure you don't have any accidental files added that are causing this. On a fresh clone, I don't see this behavior.

And the fallbackScalaVersion = "2.13.8" seeting I have also seems to be ignored.

Lets look at this after everything else since there is a lot going wrong here it seems.

What I did: I've followed the https://scalameta.org/metals/docs/build-tools/gradle/#manual-installation steps and added these plugins to gradle.

Did you try the automatic way first? Did that fail and that's why you added the custom stuff?

Another information that confuses me: if I start nvim at the root directory (/home/fiatjaf/comp/sbw/) I get metals prompts and it tries to install bloop etc (but fails, tells me to look at the logs), but I don't get a .metals directory and there are no logs -- but if I start nvim at the app/ subdirectory then I get the log files and errors above.

So it really depends on what you mean by "start" at the root. For example if you just nvim . nvim-metals won't start. It's based on a filetype autocmd, so it won't actually trigger until you open an actual Scala (or java if you have it set up) file. So Can you give me an example of you having a clean workspace and exactly what file you're opening first when you see this behavior?

ckipp01 commented 2 years ago

I'm transferring this over to the main repo. I tried importing this build via VS Code and also get the same issues, so it's not something specific to nvim-metals. Just a note about all the other stuff that was mentioned, that is all taken care of, it was due to two different metals being attached at the same time. So the main issue at this point is just that the build import doesn't work for this build.

Arthurm1 commented 2 years ago

@fiatjaf This is JDK 11?

What repo is com.fiatjaf:immortan_2.13:0.7.1-SNAPSHOT in? Gradle can't find it for me...

* What went wrong:
Execution failed for task ':app:bloopInstall'.
> Could not resolve all files for configuration ':app:debugCompileClasspath'.
   > Could not find com.fiatjaf:immortan_2.13:0.7.1-SNAPSHOT.
     Required by:
         project :app
ckipp01 commented 2 years ago

@Arthurm1 teach me obi wan, how did you get that info? I ran with --info and I get close, --trace gave me more, but still not what I wanted. I tried --debug but that was nuts and I still didn't see it.

fiatjaf commented 2 years ago

It's JDK 11, yes.

Sorry, that SNAPSHOT thing is published locally, but it should work if you replace it for com.fiatjaf:immortan_2.13:0.7.0.

Arthurm1 commented 2 years ago

@ckipp01 I ran ./gradlew projects to just get some info. That immediately failed with Unsupported class file major version 61 (Gradle 6.6 doesn't support jdk17) so I switched from JDK 17 to JDK 8 and ran again and got has been compiled by a more recent version of the Java Runtime (class file version 55.0) so I switched to JDK 11 and got...

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'Open Bitcoin Wallet'
\--- Project ':app'

I added the standard Bloop plugin setup...

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'ch.epfl.scala:gradle-bloop_2.12:1.5.0-22-91111c15'
    }
}

// test if applied first so works with Metals
if (!plugins.hasPlugin("bloop")) {
    apply plugin: "bloop"
}

Then ran ./gradlew bloopInstall and got...

BUILD FAILED in 1s
(base) root@ARTHURM3:~/obw# ./gradlew bloopInstall
> Task :app:bloopInstall FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:bloopInstall'.
> Could not resolve all files for configuration ':app:debugCompileClasspath'.
   > Could not find com.fiatjaf:immortan_2.13:0.7.1-SNAPSHOT.
     Required by:
         project :app

Gradle Android is a bit funny in that it's not possible to resolve dependencies in an Android project without building it. That's true even though we don't use the build output in any way - it's just a strange way for the Android plugin to resolve jar dependencies. So I thought that maybe the dependency was missing because it wasn't built. So ran ./gradlew assemble and got the same error.

On maven com.fiatjaf:immortan_2.13:0.7.0 exists so I've switched to that in the build and re-run ./gradlew assemble and now it compiles for ages and I get...

* What went wrong:
Execution failed for task ':app:mergeDexRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
     Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
     Type co.nstant.in.cbor.CborDecoder$1 is defined multiple times: /root/obw/app/build/intermediates/project_dex_archive/release/out/co/nstant/in/cbor/CborDecoder$1.dex, /root/obw/app/build/intermediates/external_libs_dex/release/mergeExtDexRelease/classes.dex

Not sure what that means - Android stuff.

Attempting the install again: ./gradlew bloopInstall leads to... image

Arthurm1 commented 2 years ago

@ckipp01 I often use the --stacktrace option e.g. ./gradlew bloopInstall --stacktrace to get the detail but I didn't need it here.

Arthurm1 commented 2 years ago

@fiatjaf What's the current error you're getting when trying ./gradlew bloopInstall?

ckipp01 commented 2 years ago

@ckipp01 I often use the --stacktrace option e.g. ./gradlew bloopInstall --stacktrace to get the detail but I didn't need it here.

Super, thanks for the detailed explanation!

fiatjaf commented 2 years ago

I get Task 'bloopInstall' not found in root project 'Open Bitcoin Wallet'..

But if I add the bloop config

--- a/build.gradle
+++ b/build.gradle
@@ -7,10 +7,12 @@ buildscript {
     dependencies {
         classpath 'com.android.tools.build:gradle:4.0.2'
         classpath 'scala.android.plugin:scala-android-plugin:20210222.1057'
+        classpath 'ch.epfl.scala:gradle-bloop_2.12:1.5.0-22-91111c15'
     }
 }

 allprojects {
+    apply plugin: bloop.integrations.gradle.BloopPlugin
     repositories {
         mavenLocal()
         google()

I get BUILD SUCCESSFUL.

Then I can open a Scala file, Metals asks me to import build, then it shows this:

Setting Metals Java Home will result in updating Bloop's global Json file, by Metals.
Bloop will need to be restarted in order for these changes to take effect.

Request Actions:
1. Apply and restart Bloop
2. Not now
Type number and <Enter> or click with the mouse (q or empty cancels):

I answer 1 and it says LSP[metals][Warning] Import project partially failed, limited functionality may work in some parts of the workspace. See the logs for more details.

Then in the logs I see a bunch of weird things:

2022.06.15 13:02:01 INFO  tracing is disabled for protocol LSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/fiatjaf/comp/obw/.metals/lsp.trace.json or /home/fiatjaf/.cache/metals/lsp.trace.json
2022.06.15 13:02:02 INFO  logging to file /home/fiatjaf/comp/obw/.metals/metals.log
2022.06.15 13:02:02 INFO  Started: Metals version 0.11.6 in workspace '/home/fiatjaf/comp/obw' for client Neovim 0.7.0.
2022.06.15 13:02:02 INFO  time: initialize in 0.79s
2022.06.15 13:02:03 WARN  Flyway upgrade recommended: H2 2.1.212 is newer than this version of Flyway and support has not been tested. The latest supported version of H2 is 2.1.210.
2022.06.15 13:02:03 INFO  Attempting to connect to the build server...
2022.06.15 13:02:02 INFO  skipping build import with status 'Failed'
2022.06.15 13:02:04 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/fiatjaf/comp/obw/.metals/bsp.trace.json or /home/fiatjaf/.cache/metals/bsp.trace.json
2022.06.15 13:02:04 INFO  time: Connected to build server in 0.59s
2022.06.15 13:02:04 INFO  Connected to Build server: Bloop v1.5.0-18-003e6c7b
2022.06.15 13:02:04 INFO  time: Imported build in 0.15s
2022.06.15 13:02:09 WARN  Could not find java sources in /usr/lib/jvm/src.zip, /usr/lib/jvm/lib/src.zip, /usr/lib/jvm/java-11-openjdk/src.zip, /usr/lib/jvm/java-11-openjdk/lib/src.zip. Java symbols will not be available.
2022.06.15 13:02:09 WARN  Could not find java sources in /usr/lib/jvm/src.zip, /usr/lib/jvm/lib/src.zip, /usr/lib/jvm/java-11-openjdk/src.zip, /usr/lib/jvm/java-11-openjdk/lib/src.zip. Java symbols will not be available.
2022.06.15 13:02:09 INFO  time: indexed workspace in 5.13s
2022.06.15 13:02:09 INFO  compiling app-release (30 scala sources and 361 java sources)
2022.06.15 13:02:09 ERROR error while loading package, class file '/home/fiatjaf/.gradle/caches/modules-2/files-2.1/com.softwaremill.quicklens/quicklens_2.13/1.8.4/8aa79570b8b3ce1beef93cedc8422f506ea56625/quicklens_2.13-1.8.4.jar(com/softwaremill/quicklens/package.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of package.class: Scala signature package has wrong version
 expected: 5.0
 found: 5.2 in package.class)
2022.06.15 13:02:09 ERROR error while loading package, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(fr/acinq/bitcoin/package.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of package.class: Scala signature package has wrong version
 expected: 5.0
 found: 5.2 in package.class)
2022.06.15 13:02:09 ERROR error while loading package, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(fr/acinq/eclair/package.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of package.class: Scala signature package has wrong version
 expected: 5.0
 found: 5.2 in package.class)
2022.06.15 13:02:09 ERROR error while loading Tools, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(immortan/crypto/Tools.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of Tools.class: Scala signature Tools has wrong version
 expected: 5.0
 found: 5.2 in Tools.class)
2022.06.15 13:02:09 ERROR error while loading package, class file '/home/fiatjaf/.gradle/caches/modules-2/files-2.1/io.reactivex/rxscala_2.13/0.27.0/a3bfb7e2f649e01672b5b6b00b2031521ef61621/rxscala_2.13-0.27.0.jar(rx/lang/scala/package.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of package.class: Scala signature package has wrong version
 expected: 5.0
 found: 5.2 in package.class)
2022.06.15 13:02:09 ERROR error while loading package, class file '/home/fiatjaf/.m2/repository/org/scodec/scodec-core_2.13/1.11.9/scodec-core_2.13-1.11.9.jar(scodec/package.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of package.class: Scala signature package has wrong version
 expected: 5.0
 found: 5.2 in package.class)
2022.06.15 13:02:09 ERROR error while loading package, class file '/home/fiatjaf/.gradle/caches/modules-2/files-2.1/org.scodec/scodec-bits_2.13/1.1.14/b5d33af8a804d7b5e1184cce7a7528033652e2ab/scodec-bits_2.13-1.1.14.jar(scodec/bits/package.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of package.class: Scala signature package has wrong version
 expected: 5.0
 found: 5.2 in package.class)
2022.06.15 13:02:09 ERROR error while loading MilliSatoshi, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(fr/acinq/eclair/MilliSatoshi.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of MilliSatoshi.class: Scala signature MilliSatoshi has wrong version
 expected: 5.0
 found: 5.2 in MilliSatoshi.class)
2022.06.15 13:02:09 ERROR error while loading LNParams, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(immortan/LNParams.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of LNParams.class: Scala signature LNParams has wrong version
 expected: 5.0
 found: 5.2 in LNParams.class)
2022.06.15 13:02:09 ERROR error while loading Channel, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(immortan/Channel.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of Channel.class: Scala signature Channel has wrong version
 expected: 5.0
 found: 5.2 in Channel.class)
2022.06.15 13:02:09 ERROR error while loading InputParser, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(immortan/utils/InputParser.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of InputParser.class: Scala signature InputParser has wrong version
 expected: 5.0
 found: 5.2 in InputParser.class)
2022.06.15 13:02:09 ERROR error while loading ElectrumEclairWallet, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(fr/acinq/eclair/blockchain/electrum/ElectrumEclairWallet.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of ElectrumEclairWallet.class: Scala signature ElectrumEclairWallet has wrong version
 expected: 5.0
 found: 5.2 in ElectrumEclairWallet.class)
2022.06.15 13:02:09 ERROR error while loading BitcoinUri, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(immortan/utils/BitcoinUri.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of BitcoinUri.class: Scala signature BitcoinUri has wrong version
 expected: 5.0
 found: 5.2 in BitcoinUri.class)
2022.06.15 13:02:09 ERROR error while loading Denomination, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(immortan/utils/Denomination.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of Denomination.class: Scala signature Denomination has wrong version
 expected: 5.0
 found: 5.2 in Denomination.class)
2022.06.15 13:02:10 ERROR error while loading DeterministicWallet, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(fr/acinq/bitcoin/DeterministicWallet.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of DeterministicWallet.class: Scala signature DeterministicWallet has wrong version
 expected: 5.0
 found: 5.2 in DeterministicWallet.class)
2022.06.15 13:02:10 ERROR error while loading ImplicitJsonFormats, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(immortan/utils/ImplicitJsonFormats.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of ImplicitJsonFormats.class: Scala signature ImplicitJsonFormats has wrong version
 expected: 5.0
 found: 5.2 in ImplicitJsonFormats.class)
2022.06.15 13:02:10 ERROR error while loading package, class file '/home/fiatjaf/.gradle/caches/modules-2/files-2.1/io.spray/spray-json_2.13/1.3.5/34b3a148e57870e30b797a636d0ae8eb1a1fcc99/spray-json_2.13-1.3.5.jar(spray/json/package.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of package.class: Scala signature package has wrong version
 expected: 5.0
 found: 5.2 in package.class)
2022.06.15 13:02:10 ERROR error while loading FeeratePerByte, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(fr/acinq/eclair/blockchain/fee/FeeratePerByte.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of FeeratePerByte.class: Scala signature FeeratePerByte has wrong version
 expected: 5.0
 found: 5.2 in FeeratePerByte.class)
2022.06.15 13:02:10 ERROR error while loading ThrottledWork, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(immortan/utils/ThrottledWork.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of ThrottledWork.class: Scala signature ThrottledWork has wrong version
 expected: 5.0
 found: 5.2 in ThrottledWork.class)
2022.06.15 13:02:10 ERROR error while loading FeeratePerKw, class file '/home/fiatjaf/.m2/repository/com/fiatjaf/immortan_2.13/0.7.1-SNAPSHOT/immortan_2.13-0.7.1-SNAPSHOT.jar(fr/acinq/eclair/blockchain/fee/FeeratePerKw.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of FeeratePerKw.class: Scala signature FeeratePerKw has wrong version
 expected: 5.0
 found: 5.2 in FeeratePerKw.class)
2022.06.15 13:02:11 INFO  Disconnecting from Bloop session...
2022.06.15 13:02:13 ERROR timeout: build server 'bloop' during shutdown
2022.06.15 13:02:13 INFO  Attempting to connect to the build server...
2022.06.15 13:02:15 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/fiatjaf/comp/obw/.metals/bsp.trace.json or /home/fiatjaf/.cache/metals/bsp.trace.json
2022.06.15 13:02:15 INFO  time: Connected to build server in 2.62s
2022.06.15 13:02:15 INFO  Connected to Build server: Bloop v1.5.0-18-003e6c7b
2022.06.15 13:02:15 INFO  shutting down Metals
2022.06.15 13:02:15 INFO  time: Imported build in 0.13s
2022.06.15 13:02:15 INFO  Shut down connection with build server.
2022.06.15 13:02:16 ERROR Unexpected error initializing server
scala.meta.internal.metals.MetalsBspException: BSP connection failed in the attempt to get: CompileResult.  Boxed Exception
    at scala.meta.internal.metals.BuildServerConnection$$anonfun$1.$anonfun$applyOrElse$4(BuildServerConnection.scala:300)
    at scala.Option.getOrElse(Option.scala:201)
    at scala.meta.internal.metals.BuildServerConnection$$anonfun$1.applyOrElse(BuildServerConnection.scala:298)
    at scala.meta.internal.metals.BuildServerConnection$$anonfun$1.applyOrElse(BuildServerConnection.scala:286)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:490)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.lang.Thread.run(Thread.java:829)

Arthurm1 commented 2 years ago

@fiatjaf Yes - I can see that now. All compilation failures. So the import is successful (to a point)

You're using apply plugin: "scala.android"?

The Bloop plugin doesn't support that, only the Scala and Java plugins. So no Scala library or compiler info is being added to the Bloop files, hence it''s struggling to compile the Scala files.

I can have a look at adding support - not sure how difficult it will be - I've not seen this plugin before.

Arthurm1 commented 2 years ago

@fiatjaf Is this plugin still supported? The last commit was 6 years ago and the supported Scala and Gradle versions are very old... image

Arthurm1 commented 2 years ago

@fiatjaf Which dependency is the com.samourai.wallet.schnorr.Schnorr class coming from?

fiatjaf commented 2 years ago

This is the plugin I'm using: https://github.com/dsvdsv/scala-android-plugin

I don't think there are many people using it though, probably none, but compilation works fine. Maybe there is a way for me to hardcode something on the Metals/Bloop side to make it recognize things even if it doesn't understand the plugin?

I was actually thinking about making a build.sbt file with the dependencies just so Metals would work without actually trying to resolve the Android stuff etc.

fiatjaf commented 2 years ago

Sorry for taking so long to reply, there are way too many things happening here today.

That com.samourai.wallet thing is not declared anywhere. I removed it since it wasn't being used, but now that you mention I see it being used in a test. I should remove that test since it's not needed.

Arthurm1 commented 2 years ago

@fiatjaf OK - well I can get it building but only by manually creating a scala section in the .bloop files which isn't sustainable. So Bloop + Metals will work for you but the Gradle plugin doesn't understand scala settings defined by https://github.com/dsvdsv/scala-android-plugin

I'll take a look at it but I doubt I'll have anything soon. The plugins can get horrendously complicated but, fingers crossed, it might just be a case of extracting the scala settings as the dependencies and source paths seem to extract ok.

If you're interested, the section I added to all 3 .json files was


        "scala": {
            "organization": "org.scala-lang",
            "name": "scala-compiler",
            "version": "2.13.8",
            "options": [
                "-target:jvm-1.8",
                "-Yrangepos",
                "-Wunused",
                "-Wconf:msg=parameter value .+ in anonymous function:silent",
                "-Wconf:src=*.ScaladocParser.scala&msg=parameter value (pos|message) in method reportError:silent",
                "-Wconf:src=*.Completions.scala&msg=parameter value (member|m) in method (isCandidate|isPrioritized):silent",
                "-Wconf:src=*.JavaMtags.scala&msg=parameter value (ctor|method) in method (visitConstructor|visitMethod):silent",
                "-Wconf:src=*.MtagsIndexer.scala&msg=parameter value owner in method visitOccurrence:silent",
                "-Wconf:src=.*(CompletionProvider|ArgCompletions|Completions|Keywords|IndentOnPaste).scala&msg=The outer reference:silent",
                "-Wconf:src=*.BasePCSuite.scala&msg=parameter value (scalaVersion|classpath) in method (extraDependencies|scalacOptions):silent",
                "-Xplugin:/root/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/semanticdb-scalac_2.13.8/4.5.9/semanticdb-scalac_2.13.8-4.5.9.jar"
            ],
            "jars": [
                "/root/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.8/scala-library-2.13.8.jar",
                "/root/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.8/scala-compiler-2.13.8.jar",
                "/root/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.8/scala-reflect-2.13.8.jar",
                "/root/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline/3.21.0/jline-3.21.0.jar",
                "/root/.cache/coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.9.0/jna-5.9.0.jar"
            ],
            "setup": {
                "order": "mixed",
                "addLibraryToBootClasspath": true,
                "addCompilerToClasspath": false,
                "addExtraJarsToClasspath": false,
                "manageBootClasspath": true,
                "filterLibraryFromClasspath": true
            }
        },

but that uses Metals own settings for Scala and my coursier cache dir

fiatjaf commented 2 years ago

Awesome, @Arthurm1, this worked.

For future reference, I've copied the "scala" section from another project I had lying here into inside.bloop/app-debug.json (under "project") and it started working.

fiatjaf commented 2 years ago

Weirdly, I can navigate to external dependencies and I can get the type of any variable, and even Android classes are recognized, but I can't navigate internally.

If click to go to references the Metals logs output this (but nothing else happens):

2022.06.16 08:47:55 INFO  compiling app-debug (30 scala sources and 361 java sources)
2022.06.16 08:47:57 INFO  time: compiled app-debug in 2.28s

And if I click to go to definitions I get this log line:

2022.06.16 08:47:46 ERROR code navigation does not work for the file '/home/fiatjaf/comp/obw/app/src/main/scala/fiatjaf/wallet/WalletApp.scala' because the SemanticDB file '/home/fiatjaf/comp/obw/.bloop/app-debug/build/bloop-bsp-clients-classes/classes-Metals-YY4Dbl9ASMmhAl9bzFoRyw==/META-INF/semanticdb/app/src/main/scala/fiatjaf/wallet/WalletApp.scala.semanticdb' doesn't exist. There can be many reasons for this error.
Arthurm1 commented 2 years ago

@fiatjaf It works for me.

If the semantic file isn't there then it hasn't compiled properly. Probably because it thinks that it's already compiled.

You could try the Metals Recompile workspace command.

If that doesn't work - you could try deleting the directories under .bloop - NOT the .json files directly under it though. Then run the Metals restart build server command.

If neither of these work then it's probably down to the build export which we've hacked and you'll have to wait for Bloop to support that plugin