{"record":{"id":"fed395b97f8dee54","repo":"skylot/jadx","slug":"failed-to-generate-gradle-files","errorCode":null,"errorMessage":"Failed to generate gradle files","messagePattern":"Failed to generate gradle files","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/export/gen/SimpleJavaGradleGenerator.java","lineNumber":44,"sourceCode":"\t\tthis.projectDir = projectDir;\n\t\tthis.resources = resources;\n\t}\n\n\t@Override\n\tpublic void init() {\n\t\tappDir = new File(projectDir, \"app\");\n\t\tFile srcOutDir = new File(appDir, \"src/main/java\");\n\t\tFile resOutDir = new File(appDir, \"src/main/resources\");\n\t\toutDirs = new OutDirs(srcOutDir, resOutDir);\n\t}\n\n\t@Override\n\tpublic void generateFiles() {\n\t\ttry {\n\t\t\tsaveSettingsGradle();\n\t\t\tsaveBuildGradle();\n\t\t} catch (Exception e) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to generate gradle files\", e);\n\t\t}\n\t}\n\n\tprivate void saveSettingsGradle() throws IOException {\n\t\tTemplateFile tmpl = loadGradleTemplate(\"/export/java/settings.gradle.kts.tmpl\");\n\t\ttmpl.add(\"projectName\", GradleGeneratorTools.guessProjectName(root));\n\t\ttmpl.save(new File(projectDir, \"settings.gradle.kts\"));\n\t}\n\n\tprivate void saveBuildGradle() throws IOException {\n\t\tTemplateFile tmpl = loadGradleTemplate(\"/export/java/build.gradle.kts.tmpl\");\n\t\ttmpl.save(new File(appDir, \"build.gradle.kts\"));\n\t}\n\n\tprivate TemplateFile loadGradleTemplate(String templatePath) throws FileNotFoundException {\n\t\tTemplateFile tmpl = TemplateFile.fromResources(templatePath);\n\t\tIJadxSecurity security = root.getArgs().getSecurity();\n\t\ttmpl.setValueSanitizer(str -> security.sanitizeString(str, SanitizeType.GRADLE_KOTLIN));","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/export/gen/SimpleJavaGradleGenerator.java#L26-L62","documentation":"Thrown as JadxRuntimeException by SimpleJavaGradleGenerator.generateFiles() wrapping any exception during settings.gradle.kts or build.gradle.kts generation. This generator handles the SIMPLE_JAVA export type (non-Android projects). The original exception is attached as the cause for diagnosis.","triggerScenarios":"Any exception during saveSettingsGradle() or saveBuildGradle(). Common causes: IOException from file writes, FileNotFoundException if the /export/java/*.kts.tmpl template resources are missing from the classpath, or JadxRuntimeException from template variable resolution failures (unknown variable, malformed template).","commonSituations":"Exporting a plain Java JAR as a Gradle project. Fails with missing templates if the jadx-core JAR is incomplete or the resources were stripped. Fails with I/O errors on read-only or full output directories.","solutions":["Inspect getCause() to identify the root exception type.","Verify the output project directory is writable.","Ensure the jadx distribution is complete (templates under /export/java/ must be present in the jadx-core JAR).","If the cause is an unknown template variable, report to jadx developers."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify template resources are present before export\nif (TemplateFile.class.getResource(\"/export/java/settings.gradle.kts.tmpl\") == null) {\n    throw new IllegalStateException(\"Gradle templates missing from classpath\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    exportGradle.generateGradleFiles();\n} catch (JadxRuntimeException e) {\n    Throwable cause = e.getCause();\n    LOG.error(\"Simple Java Gradle export failed. Root cause: {}\", cause.getMessage(), cause);\n}","preventionTips":["Inspect getCause() to distinguish I/O errors from template errors.","Verify the jadx distribution includes /export/java/*.tmpl resources.","Check output directory permissions before export."],"tags":["jadx","gradle-export","java","io","wrapper-exception","template"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}