Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No build target" when importing a Gradle multi module build #2704

Closed
gravelld opened this issue Apr 12, 2021 · 5 comments
Closed

"No build target" when importing a Gradle multi module build #2704

gravelld opened this issue Apr 12, 2021 · 5 comments

Comments

@gravelld
Copy link

gravelld commented Apr 12, 2021

I have a Gradle multi module build. Most of the sub projects are Java, but some are Scala. I want to use vscode and metals to develop this code.

When I import this code into vscode I get:

2021.04.12 17:37:04 INFO  running '/tmp/metals6594707459598176680/gradlew --console=plain --init-script /tmp/metals6594707459598176680/init-script.gradle bloopInstall'
2021.04.12 17:37:05 INFO  > Task :configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.analytics:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.analytics:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.api:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.api:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.bootstrap:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.bootstrap:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.build.base:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.build.base:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.charge.api:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.charge.api:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.configuration.file:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.configuration.file:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.licence:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.licence:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.logging:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.logging:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.main:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.main:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.model:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.model:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.model.api:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.model.api:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.music.info.api:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.music.info.api:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.music.info.common:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.music.info.common:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.music.info.onemusicapi:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.music.info.onemusicapi:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.music.info.tagsource.api:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.music.info.tagsource.api:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.music.info.tagsource.impl:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.music.info.tagsource.impl:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.online.untaggeddb.common:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.online.untaggeddb.common:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.platform:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.platform:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.platform.integrationtest:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.platform.integrationtest:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.platform.lookup:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.platform.lookup:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.platform.lookup.mapdb:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.platform.lookup.mapdb:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.platform.storage.file.observer.filewatcher:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.platform.storage.file.observer.filewatcher:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.albumintegrity:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.albumintegrity:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.coverart.lookup.api:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.coverart.lookup.api:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.coverart.lookup.common:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.coverart.lookup.common:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.parsed:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.parsed:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.regexruleloader:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.regexruleloader:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.tag.auto:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.tag.auto:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.tag.tagtype:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.policy.tag.tagtype:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.regexrule.partofset:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.regexrule.partofset:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.regexrule.trim:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.regexrule.trim:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.ui:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.ui:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.ui.boot:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.ui.boot:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.ui.systemtray:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.ui.systemtray:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.untagged.onemusicapi:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.untagged.onemusicapi:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.update.getdown:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.update.getdown:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.web.debug:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.bliss.web.debug:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.google.gson:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.google.gson:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.util:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.elsten.util:bloopInstall
2021.04.12 17:37:05 INFO  > Task :com.onemusicapi.client:configureBloopInstall
2021.04.12 17:37:05 INFO  > Task :com.onemusicapi.client:bloopInstall
2021.04.12 17:37:05 INFO  
2021.04.12 17:37:05 INFO  BUILD SUCCESSFUL in 1s
2021.04.12 17:37:05 INFO  82 actionable tasks: 82 executed
2021.04.12 17:37:05 INFO  gradle bloopInstall exit: 0
2021.04.12 17:37:06 INFO  time: ran 'gradle bloopInstall' in 1.68s
2021.04.12 17:37:06 INFO  Disconnecting from Bloop session...
2021.04.12 17:37:06 INFO  Shut down connection with build server.
2021.04.12 17:37:06 INFO  Attempting to connect to the build server...
2021.04.12 17:37:06 INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /home/gravelld/.cache/metals/bsp.trace.json
2021.04.12 17:37:06 INFO  time: Connected to build server in 70ms
2021.04.12 17:37:06 INFO  Connected to Build server: Bloop v1.4.8
2021.04.12 17:37:06 INFO  time: Imported build in 0.12s
2021.04.12 17:37:07 INFO  time: indexed workspace in 1.13s

All INFO so I assume that's ok.

However, no Java code that is dependent on Scala code compiles. If I click on the source .scala file to show the type that cannot be used, the metals output adds:

2021.04.12 17:37:49 WARN  no build target for: /home/gravelld/git-repo/elsten-software_bliss/com.elsten.bliss.platform.lookup/src/main/scala/com/elsten/bliss/platform/lookup/LookupResult.scala
2021.04.12 17:37:51 INFO  no build target: using presentation compiler with only scala-library: 2.12.13
2021.04.12 17:37:51 INFO  time: code lens generation in 2.13s

I've tried following the "doctor" and removing .metals and .bloop and restarting and re-importing, but the behaviour is the same.

Expected behavior

A multi module, combined Scala and Java project is imported and compiles.

Installation:

  • Operating system: Linux
  • Editor: Visual Studio Code
  • Metals version: v0.10.1

Another log I often get is:

2021.04.14 08:56:10 WARN  no build tool detected in workspace '/home/gravelld/git-repo/elsten-software_bliss'. The most common cause for this problem is that the editor was opened in the wrong working directory, for example if you use sbt then the workspace directory should contain build.sbt. 
@gravelld
Copy link
Author

In addition - could anyone advise me whether #2520 makes this pointless? There are Java-only projects as part of this multi module build, but I was hoping I could let the Java language server handle those...

@tgodzik
Copy link
Contributor

tgodzik commented Apr 13, 2021

Thanks for reporting! The real issue might not be related to that PR after all. Do you have the com.elsten.bliss.platform.lookup.json file inside .bloop directory? Does it have correct source directories defined inside?

no build target for: usually means that Metals cannot match a file to a project it belongs to. The issue might be that the project/module was badly imported (which would be an issue in the Gradle Bloop plugin) or alternatively Metals is unable to connenct to Bloop correctly, in which case we should have a trace of that in .metals/metals.log file.

Lastly, we could try looking into the BSP traces, which can be enabled as explained here:https://scalameta.org/metals/docs/contributors/getting-started.html#json-rpc-trace

It should contain exactly what info is sent to Metals and it might help us figure out why it's not finding a build target for that file.

@gravelld
Copy link
Author

Do you have the com.elsten.bliss.platform.lookup.json file inside .bloop directory? Does it have correct source directories defined inside?

Yes, and I can already see the sources setting is incorrect:

{
    "version": "1.4.0",
    "project": {
        "name": "com.elsten.bliss.platform.lookup",
        "directory": "/home/gravelld/git-repo/com.elsten.bliss.platform.lookup",
        "workspaceDir": "/home/gravelld/git-repo/elsten-software_bliss",
        "sources": [
            "/home/gravelld/git-repo/com.elsten.bliss.platform.lookup/src/main/java"
        ],
        "dependencies": [
            
        ],
        "classpath": [
            
        ],
        "out": "/home/gravelld/git-repo/elsten-software_bliss/.bloop/com.elsten.bliss.platform.lookup/build",
        "classesDir": "/home/gravelld/git-repo/elsten-software_bliss/.bloop/com.elsten.bliss.platform.lookup/build/classes",
        "resources": [
            "/home/gravelld/git-repo/com.elsten.bliss.platform.lookup/src/main/resources"
        ],
        "java": {
            "options": [
                "-source",
                "1.8",
                "-target",
                "1.8",
                "-h",
                "/home/gravelld/git-repo/com.elsten.bliss.platform.lookup/build/generated/sources/headers/java/main",
                "-g",
                "-sourcepath",
                "-proc:none",
                "-XDuseUnsharedTable=true"
            ]
        },
        "platform": {
            "name": "jvm",
            "config": {
                "home": "/usr/lib/jvm/adoptopenjdk-11-hotspot-amd64",
                "options": [
                    
                ]
            },
            "mainClass": [
                
            ],
            "classpath": [
                
            ]
        },
        "tags": [
            "library"
        ]
    }
}

I tried changing it to src/main/scala but that appears to make no difference.

There are no dependencies listed - but this project has dependencies:

apply plugin: 'scala'


// In this section you declare the dependencies for your production and test code
dependencies {
	compile libraries.javax_inject
	compile libraries.log4j

	compile project(":com.elsten.bliss.music.info.api")

	testCompile testLibraries.junit4

}

(Note there are additional configurations for the project provided by the root project).

For the server connection, here're the logs:

�[0m2021.04.14 09:04:04 INFO  Attempting to connect to the build server...�[0m
Starting the bsp launcher for bloop...
Opening a bsp server connection with 'bsp --protocol local --socket /tmp/bsp-launcher11305622012222055453/bsp.socket'...
Waiting for the bsp connection to come up...
Waiting for the bsp connection to come up...
Waiting for the bsp connection to come up...
Waiting for the bsp connection to come up...
No server running at 127.0.0.1:8212, let's fire one...
Resolving ch.epfl.scala:bloop-frontend_2.12:1.4.8...
Starting bloop server at 127.0.0.1:8212...
Attempting a connection to the server...
Attempting a connection to the server...
Attempting a connection to the server...
Attempting a connection to the server...
Attempting a connection to the server...
Attempting a connection to the server...
Attempting a connection to the server...
�[0m�[32m[D]�[0m Loading workspace settings from bloop.settings.json
�[0m�[32m[D]�[0m Loading 42 projects from '/home/gravelld/git-repo/elsten-software_bliss/.bloop'...
...

I think that's starting and connecting.

Lastly, we could try looking into the BSP traces, which can be enabled as explained here:https://scalameta.org/metals/docs/contributors/getting-started.html#json-rpc-trace

Here's a trace after restarting VS Code and opening a Scala file to trigger Metals to launch:

bsp.trace.json.gz

@tgodzik
Copy link
Contributor

tgodzik commented Apr 14, 2021

Thanks for the additional info! It looks like maybe the build is missing:

compile group: 'org.scala-lang', name: 'scala-library', version: '2.12.13'

I think without it we might be exporting it as a java project.

I base it on some test in Bloop for the gradle integration:
https://github.com/scalacenter/bloop/blob/master/integrations/gradle-bloop/src/test/scala/bloop/integrations/gradle/ConfigGenerationSuite.scala

and it seems to be required by Gradle?

https://docs.gradle.org/current/userguide/scala_plugin.html#sec:scala_dependency_management

I am not that familiar with the Gradle integration however, so I might not be right here.

@tgodzik
Copy link
Contributor

tgodzik commented Apr 14, 2021

Ok, it seems to also be suggested in scalacenter/bloop#1488 (comment)

I will close this one and we can continue the discussion there.

@tgodzik tgodzik closed this as completed Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants