{"record":{"id":"6b2affdb42026402","repo":"gradle/gradle","slug":"the-java-plugin-must-be-applied-to-access-the-defa","errorCode":null,"errorMessage":"The Java plugin must be applied to access the default test suite.","messagePattern":"The Java plugin must be applied to access the default test suite\\.","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"platforms/jvm/plugins-java/src/main/java/org/gradle/api/plugins/internal/JavaPluginHelper.java","lineNumber":66,"sourceCode":"\n        if (!(component instanceof JvmSoftwareComponentInternal)) {\n            throw new GradleException(\"The Java plugin must be applied to access the java component.\");\n        }\n\n        return (JvmSoftwareComponentInternal) component;\n    }\n\n    /**\n     * Gets the default test suite. This method assumes the Java plugin is applied.\n     *\n     * @throws GradleException If the default test suite does not exist.\n     */\n    public static JvmTestSuite getDefaultTestSuite(Project project) {\n        String message = \"The Java plugin must be applied to access the default test suite.\";\n\n        TestingExtension testing = project.getExtensions().findByType(TestingExtension.class);\n        if (testing == null) {\n            throw new GradleException(message);\n        }\n\n        TestSuite defaultTestSuite = testing.getSuites().findByName(JvmTestSuitePlugin.DEFAULT_TEST_SUITE_NAME);\n        if (!(defaultTestSuite instanceof JvmTestSuite)) {\n            throw new GradleException(message);\n        }\n\n        return (JvmTestSuite) defaultTestSuite;\n    }\n}\n","sourceCodeStart":48,"sourceCodeEnd":77,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/jvm/plugins-java/src/main/java/org/gradle/api/plugins/internal/JavaPluginHelper.java#L48-L77","documentation":"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.'","triggerScenarios":"Calling JavaPluginHelper.getDefaultTestSuite — directly or via tooling built on it — in a project where neither the java plugin nor jvm-test-suite is applied.","commonSituations":"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.","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."],"exampleFix":"// before — helper used on a project without java/jvm-test-suite\n\n// after\nplugins { id 'java' }  // exposes TestingExtension and the default test suite","handlingStrategy":"validation","validationCode":"// verify the testing extension exists before using test-suite helpers\ndef testing = project.extensions.findByType(TestingExtension)\nif (testing == null) {\n    throw new GradleException('Apply the java plugin (or jvm-test-suite) before configuring test suites')\n}\ndef suite = testing.suites.findByName('test')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["gradle","java-plugin","test-suites","internal-api","plugin-not-applied"],"backgroundTag":"plugin-not-applied","analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}