Skip to content

Support Scala in Gradle projects#3734

Open
snjeza wants to merge 1 commit intoeclipse-jdtls:mainfrom
snjeza:issue-4358
Open

Support Scala in Gradle projects#3734
snjeza wants to merge 1 commit intoeclipse-jdtls:mainfrom
snjeza:issue-4358

Conversation

@snjeza
Copy link
Contributor

@snjeza snjeza commented Mar 9, 2026

@snjeza
Copy link
Contributor Author

snjeza commented Mar 10, 2026

test this please

Comment on lines +188 to +189
default void cleanScalaProjects(IProgressMonitor monitor) {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fond of this idea. This is a Buildship specific implementation detail that leaks to the API level. Could we avoid that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn’t related to Buildship. Gradle Tooling API expects Scala IDE to exist, adds SCALA_CONTAINER and removes some scala libraries.
Buildship will just take what Tooling API send to it. See
https://github.com/gradle/gradle/blob/b3c5d40e82439da4627b38b4ced93121e551b0eb/platforms/ide/ide-plugins/src/main/java/org/gradle/plugins/ide/eclipse/EclipsePlugin.java#L375-L377
Since Scala IDE doesn’t exist in VS Code, we need to add missing libraries and remove natures, builders and classpath containers that Java LS doesn’t recognize. If someone adds an extension that introduces the Scala Container, builder and nature, the cleanScalaProjects method won’t do anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still, that is a very gradle-specific implementation detail. Why can't we call the cleanScalaProjects() implementation directly at the start of the GradleBuildSupport.compile(...) method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not call the cleanScalaProjects method whenever the compile method is called.
I removed this method from IBuildSupport.

ProjectsManager projectsManager = JavaLanguageServerPlugin.getProjectsManager();
if (projectsManager != null) {
projectsManager.buildSupports().forEach(bs -> {
bs.cleanScalaProjects(monitor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yuck

*/
public class SearchUtils {

private static final class SearchClassVisitor extends ClassVisitor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you document what this class does and why is there something scala-specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

wp.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iterates through ALL workspace projects for every built project : O(n²) complexity for workspace with many projects 😱
Why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a gradle module has a kotlin, scala, aspectj or a groovy task, these tasks will be executed in all submodules.
If we don’t refresh submodules, JavaLS won’t create diagnostics correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we at least filter only gradle projects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

private void publishDiagnostics(String error, boolean parseKotlin, boolean parseGroovy, boolean parseAspectj) {
private void publishDiagnostics(String error, boolean parseKotlin, boolean parseGroovy, boolean parseAspectj, boolean parseScala) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you wrap those booleans into a ParsingOptions record?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return tempInit;
}

private static void process(IProject project, String output, IProgressMonitor monitor) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some documentation explaining what this large method does.
You can also try to break it down into several simpler pieces of code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return null;
}

// Gradle Tooling API removes several scala libraries and adds the Scala builder and container that aren't recognized by Java LS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe check if the plugin responsible for this Scala builder/container is present in this eclipse/jdt.ls instance, just in case we don't break someone already integrating scala with jdt.ls (unlikely but still)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanScalaProjects method checks all builders, natures, classpath containers and removes those that Java LS doesn’t recognize. We won’t break anyone. If Java LS recognizes a builder, nature or a classpath container, they won’t be removed.

@snjeza
Copy link
Contributor Author

snjeza commented Mar 18, 2026

@fbricon I have updated the PR.

@snjeza
Copy link
Contributor Author

snjeza commented Mar 24, 2026

@fbricon I have updated the PR.

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

Successfully merging this pull request may close these issues.

Support Scala in Gradle projects

2 participants