gradle/gradle · error · GradleException
The Java plugin must be applied to access the default test s
Error message
The Java plugin must be applied to access the default test suite.
What it means
getDefaultTestSuite first requires the TestingExtension (created by the jvm-test-suite plugin, which the java plugin applies). When the extension is missing, the lookup fails and Gradle throws GradleException: 'The Java plugin must be applied to access the default test suite.'
Source
Thrown at platforms/jvm/plugins-java/src/main/java/org/gradle/api/plugins/internal/JavaPluginHelper.java:66
if (!(component instanceof JvmSoftwareComponentInternal)) {
throw new GradleException("The Java plugin must be applied to access the java component.");
}
return (JvmSoftwareComponentInternal) component;
}
/**
* Gets the default test suite. This method assumes the Java plugin is applied.
*
* @throws GradleException If the default test suite does not exist.
*/
public static JvmTestSuite getDefaultTestSuite(Project project) {
String message = "The Java plugin must be applied to access the default test suite.";
TestingExtension testing = project.getExtensions().findByType(TestingExtension.class);
if (testing == null) {
throw new GradleException(message);
}
TestSuite defaultTestSuite = testing.getSuites().findByName(JvmTestSuitePlugin.DEFAULT_TEST_SUITE_NAME);
if (!(defaultTestSuite instanceof JvmTestSuite)) {
throw new GradleException(message);
}
return (JvmTestSuite) defaultTestSuite;
}
}
View on GitHub (pinned to 534f27719b)
Solutions
- Apply the java plugin — it brings jvm-test-suite and creates the default 'test' suite.
- Or apply 'jvm-test-suite' explicitly if you only need the testing extension.
- Guard custom logic: only invoke the helper when TestingExtension is present.
Example fix
// before — helper used on a project without java/jvm-test-suite
// after
plugins { id 'java' } // exposes TestingExtension and the default test suite Defensive patterns
Strategy: validation
Validate before calling
// verify the testing extension exists before using test-suite helpers
def testing = project.extensions.findByType(TestingExtension)
if (testing == null) {
throw new GradleException('Apply the java plugin (or jvm-test-suite) before configuring test suites')
}
def suite = testing.suites.findByName('test') Prevention
- Apply the java plugin first in any project that touches the default test suite.
- Check for the TestingExtension before configuring suites in shared build logic.
When it happens
Trigger: Calling JavaPluginHelper.getDefaultTestSuite — directly or via tooling built on it — in a project where neither the java plugin nor jvm-test-suite is applied.
Common situations: Plugins or build logic assuming a standard Java setup, applied to plain or non-Java projects; test-suite-dependent tooling applied to a project with only the base plugin.
Related errors
- The Java plugin must be applied to access the java component
- Cannot clear '%s' as it is a filtered collection
- Cannot create DslObject for '%s' (class: %s) as it does not
- DeprecationLogger has not been initialized. Most probably, i
- A description must be specified before this operation is sta
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/6b2affdb42026402.
Report an issue: GitHub.