-
Notifications
You must be signed in to change notification settings - Fork 73
Closed
Labels
Description
Environment
- Extension: Gradle for Java (
vscjava.vscode-gradle) 3.17.1 (server plugin bundled in extension) - OS: macOS 15.5 (x86_64)
- Gradle: 9.2.0
- Groovy: 4.0.28
- Java: OpenJDK 21.0.9 (Zulu)
- Project: simple multi-project Java build with
rootProject.name = 'CPT111-Group76'and subprojectapp
Summary
When the vscjava.vscode-gradle extension injects its init.gradle (which adds plugin-0.4.0.jar to the initscript classpath and then applies com.microsoft.java.bs.gradle.plugin.GradleBuildServerPlugin), Gradle fails during initialization with:
Could not get unknown property 'com' for root project 'CPT111-Group76' of type org.gradle.api.Project.
This prevents the Java Language Server from importing the workspace. Disabling the extension makes the project import successfully.
Reproduction steps
- Open the Java project in VS Code with
vscjava.vscode-gradleenabled. - The extension injects an init script located at
<extension>/server/plugins/init.gradlewith (simplified):
initscript {
dependencies {
classpath files('plugin-0.4.0.jar')
}
}
allprojects {
apply plugin: com.microsoft.java.bs.gradle.plugin.GradleBuildServerPlugin
}- The VS Code Java Language Server / Gradle tooling client fails to import build targets and logs the MissingPropertyException.
Observed logs
- Excerpt from the language server / extension logs:
[Error] Initialization failed
java.util.concurrent.CompletionException: ... Could not get unknown property 'com' for root project 'CPT111-Group76' of type org.gradle.api.Project.
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'com' for root project 'CPT111-Group76' of type org.gradle.api.Project.
at init_...(/.../init.gradle:8)
- Running from terminal with the extension init script reproduces the same error:
./gradlew --init-script /.../init.gradle tasks --stacktrace
FAILURE: Build failed with an exception.
* Where:
Initialization script '/.../init.gradle' line: 8
* What went wrong:
Could not get unknown property 'com' for root project 'CPT111-Group76' of type org.gradle.api.Project.
Notes about attempts to workaround
- I tried creating a
plugin-0.4.0.jarfile in the project root (and also a symlink pointing to the extension'splugin-0.4.0.jar) so thatinitscript { classpath files('plugin-0.4.0.jar') }can find the jar. The jar is present and containscom.microsoft.java.bs.gradle.plugin.GradleBuildServerPlugin, but the init script still throws the MissingPropertyException when evaluating theapply plugin: com.microsoft...line. It appears Groovy may parse the bare class reference before the class is available in the classloader, causingcomto be treated as an unknown property of theProjectobject.
Why this is likely a classloading/parse-time issue
- The error indicates Groovy tried to resolve
comas a property on theProject(MissingPropertyException) instead of recognizing it as a package/class reference, which suggests the plugin class wasn't resolvable at that parse time or that the script evaluation order makes the bare reference unsafe. - Different Gradle/Groovy versions can change script parsing/classloading timing. In my environment (Gradle 9.2.0, Groovy 4.0.28) the injected script fails to apply the plugin using the bare class reference.
Suggested fixes / mitigation options
- Use safe plugin application in
init.gradle:- After adding classpath, attempt to load the class via classloader and apply via
project.plugins.apply(pluginClass), wrapped in try/catch. Example:
- After adding classpath, attempt to load the class via classloader and apply via
initscript {
dependencies {
classpath files('plugin-0.4.0.jar')
}
}
allprojects {
try {
def pluginClass = this.class.classLoader.loadClass('com.microsoft.java.bs.gradle.plugin.GradleBuildServerPlugin')
project.getPlugins().apply(pluginClass)
} catch (Throwable t) {
// Log and continue without failing the build initialization
}
}- If the plugin is or can be published with a plugin id, prefer applying by id (string) instead of a bare class reference:
apply plugin: 'com.microsoft.java.bs.gradle.plugin' // if published as plugin id-
Add defensive checks in the injected init script to avoid throwing during project configuration time; if a class can't be loaded, skip applying the plugin and log a clear warning.
-
Document the compatibility matrix for injected init scripts vs Gradle/Groovy versions and provide a toggle for users to opt-out of init script injection.
Request
- Please consider changing the injected
init.gradleto apply the plugin in a way that won't throwMissingPropertyExceptionduring Gradle initialization (see suggested code above). - If you need further logs, I can attach the full
client.logand the terminal stacktrace output.
Local environment summary (collected):
- Gradle 9.2.0 (Launcher JVM: 21.0.9)
- Groovy 4.0.28
- Java: OpenJDK 21.0.9 (Zulu)
- OS: macOS 15.5 x86_64
- Extension version tested:
vscjava.vscode-gradle3.17.1
chagong