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

Groovy plugin classpath not loading files in the same directory #183

Open
jordanrobinson opened this issue Jul 4, 2024 · 2 comments
Open

Comments

@jordanrobinson
Copy link

Hi there, first off thanks so much for your excellent plugin.

I've been having an issue with live plugins when they use other Groovy scripts in the same directory. For example, in the situation where there is this folder structure:

2024-07-04_09-47-40@2x

Where plugin.groovy is

import com.intellij.openapi.diagnostic.Logger
import static liveplugin.PluginUtil.*

import globals

if (isIdeStartup) return

show("isIdeStartup: $isIdeStartup")
show("project: $project")
show("pluginDisposable: $pluginDisposable")
show("pluginPath: $pluginPath")

show(globals.example)

and globals.groovy being

class globals {
    static String example = "example-import-fail-replication"
}

I get the error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:file:/Users/jordanrobinson/example/.live-plugins/hello-world-test/plugin.groovy: 4: unable to resolve class globals @ line 4, column 1.   import globals   ^1 error
	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:292)
... stack trace ...

If I specify adding it to the classpath in the form

// add-to-classpath /Users/jordanrobinson/example/.live-plugins/hello-world-test/

This works fine, but this isn't really a workable solution as my team currently have a few live plugins with various files and most people on the team do not have this issue, while 3-4 people do.

I've tried quite a few things so far but I'm at a bit of a loss as to what to try next. Please do let me know if there's anything more I can add that would be helpful.

Versions:
GoLand 2024.1.3 GO-241.17890.21
LivePlugin 0.8.8 beta
macOS Sonoma 14.5

@dkandalov
Copy link
Owner

Hi.

Apologies for such a slow reply :(

I tried reproducing the problem in GoLand 2024.3.1 and LivePlugin (0.9.5 beta) but it seems to work 🤔
The code for running Groovy plugins hasn't change for a while and it's basically just this:

val pluginFolderUrl = "file:///${plugin.path}/"
val scriptEngine = GroovyScriptEngine(pluginFolderUrl, classLoader)
scriptEngine.loadScriptByName(mainScript.toUrlString())

where GroovyScriptEngine is bundled with Groovy so it should be pretty stable.

AFAIK Groovy version pretty much doesn't change across IDEs (and stays on version 3.0.x).
JDKs could probably be different across GoLand installations but it shouldn't make any difference.

I wonder if it could some kind of local problem (like case-sensitive files 🤷) or when copying the code I made a mistake and called the file global.groovy instead of "globals".

@TTFTCUTS
Copy link

TTFTCUTS commented Jan 23, 2025

I am also having this problem under similarly mundane circumstances, but in IntelliJ IDEA Community on Windows. Same error, unable to resolve any classes in other files.

The classpath trick isn't working for me either.

Worth noting for above that making the file name match the class name didn't help.

IntelliJ IDEA 2024.3.1.1 Community Edition
LivePlugin 0.9.5 beta
Windows 11 23H2

Edit: and now I find // depends-on-plugin doesn't seem to be working for me in the editor for Groovy? That part works when the plugin is run, but doesn't seem to be able to resolve anything in the editor. Good grief... back to a single kotlin script instead then, at least that works for now.

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

3 participants