Skip to content

Support Kotlin,Groovy in Gradle projects#3682

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

Support Kotlin,Groovy in Gradle projects#3682
snjeza wants to merge 1 commit intoeclipse-jdtls:mainfrom
snjeza:issue-4312

Conversation

@snjeza
Copy link
Contributor

@snjeza snjeza commented Jan 21, 2026

@fbricon
Copy link
Contributor

fbricon commented Jan 21, 2026

So it seems that if, after a kotlin project has been imported, if I create a new kt file, e.g. App2.kt, a copy of App.kt, and then reference it in the java file (new App2().hello();), compilation still fails.
Restarting vscode doesn't fix it. You need to clean the java language server workspace to trigger a full reimport, in order for compilation to be fixed.

Copy link
Contributor

@fbricon fbricon left a comment

Choose a reason for hiding this comment

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

adding new Kotlin or Groovy files, or adding new methods to existing ones are not visible to the java compiler, until a full reimport occurs

@@ -0,0 +1,10 @@
package org.sample;
Copy link
Contributor

Choose a reason for hiding this comment

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

should prolly go into src/main/java

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried it, but the compileGroovy task depends on the compileJava task, which compiles the Java source before the Groovy source, and can't find the App class. It fails from the Gradle command line.

@@ -0,0 +1,22 @@
apply plugin: "io.freefair.aspectj"
Copy link
Contributor

Choose a reason for hiding this comment

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

file should be deleted

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.

@@ -0,0 +1,22 @@
apply plugin: "io.freefair.aspectj"
Copy link
Contributor

Choose a reason for hiding this comment

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

file should be deleted

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.

@snjeza
Copy link
Contributor Author

snjeza commented Jan 21, 2026

So it seems that if, after a kotlin project has been imported, if I create a new kt file, e.g. App2.kt, a copy of App.kt, and then reference it in the java file (new App2().hello();), compilation still fails.
Restarting vscode doesn't fix it. You need to clean the java language server workspace to trigger a full reimport, in order for compilation to be fixed.
adding new Kotlin or Groovy files, or adding new methods to existing ones are not visible to the java compiler, until a full reimport occurs

If you change a Groovy or Kotlin class, you will need to reload the root project for the changes to be visible when running the tests. We could add *.kt and *.groovy files to VS Code watchers if the Groovy and Kotlin preferences are enabled.

@fbricon
Copy link
Contributor

fbricon commented Jan 22, 2026

If you change a Groovy or Kotlin class, you will need to reload the root project for the changes to be visible when running the tests. We could add *.kt and *.groovy files to VS Code watchers if the Groovy and Kotlin preferences are enabled.

Sounds like it's gonna be pretty slow no? if you rebuild on each kt change

@snjeza
Copy link
Contributor Author

snjeza commented Jan 22, 2026

Sounds like it's gonna be pretty slow no? if you rebuild on each kt change

Gradle supports incremental build - https://docs.gradle.org/current/userguide/incremental_build.html
I could try to run only the classes task.

@fbricon
Copy link
Contributor

fbricon commented Jan 24, 2026

Gradle supports incremental build - docs.gradle.org/current/userguide/incremental_build.html I could try to run only the classes task.

let's see how it goes

@snjeza
Copy link
Contributor Author

snjeza commented Jan 24, 2026

...I could try to run only the classes task.

let's see how it goes

I have added this feature.
You can test

Comment on lines 306 to 308
if (preferenceManager.getPreferences().isAutobuildEnabled() && ProjectUtils.isGradleProject(project)) {
if ((preferenceManager.getPreferences().isAspectjSupportEnabled() && resource.getName().endsWith(".aj")) || (preferenceManager.getPreferences().isKotlinSupportEnabled() && resource.getName().endsWith(".kt"))
|| (preferenceManager.getPreferences().isGroovySupportEnabled() && resource.getName().endsWith(".groovy"))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ProjectUtils.isGradleProject(project)) {
if ((preferenceManager.getPreferences().isAspectjSupportEnabled() && resource.getName().endsWith(".aj")) || (preferenceManager.getPreferences().isKotlinSupportEnabled() && resource.getName().endsWith(".kt"))

all that Gradle specific stuff should be moved down some IBuildSupport.shouldCompile(...) method. I'd rather prefer we avoided more build specific coupling in the managers

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.

@snjeza
Copy link
Contributor Author

snjeza commented Jan 26, 2026

@fbricon I have updated the PR.

@snjeza
Copy link
Contributor Author

snjeza commented Jan 29, 2026

@fbricon I have updated the PR.

@snjeza snjeza force-pushed the issue-4312 branch 2 times, most recently from a5a2295 to 650941d Compare January 31, 2026 18:44
@snjeza
Copy link
Contributor Author

snjeza commented Jan 31, 2026

I have added the following improvements:

  • if a groovy project contains compile errors, the build won’t fail
  • if there are compile errors in AspectJ, Groovy, Kotlin projects, they will appear when VS Code is started for the first time

@snjeza
Copy link
Contributor Author

snjeza commented Feb 1, 2026

test this please

@snjeza
Copy link
Contributor Author

snjeza commented Feb 2, 2026

test this please

polinhazn89-design

This comment was marked as spam.

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.

3 participants