JetBrains/intellij-community · error · CantRunException
No Java sources found in the selected scope
Error message
No Java sources found in the selected scope
What it means
The generator iterates the selected scope (custom scope, package, or 'whole project') collecting Java source files; if the collected 'sources' set is empty after the scan, CantRunException('No Java sources found in the selected scope') stops the run. The iteration itself is wrapped in a modal progress; an empty result means the chosen scope simply contains no compilable Java files reachable as source roots.
Source
Thrown at java/java-impl/src/com/intellij/javadoc/JavadocGeneratorRunProfile.java:250
parameters.add("-link");
parameters.add(url);
}
}
if (myConfiguration.OUTPUT_DIRECTORY != null) {
parameters.add("-d");
parameters.add(myConfiguration.OUTPUT_DIRECTORY.replace('/', File.separatorChar));
}
Set<Module> modules = new LinkedHashSet<>();
Set<VirtualFile> sources = new HashSet<>();
Runnable r = () -> myGenerationOptions.accept(new MyContentIterator(myProject, modules, sources));
String title = JavaBundle.message("javadoc.generate.sources.progress");
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(r, title, true, myProject)) {
return;
}
if (sources.isEmpty()) {
throw new CantRunException(JavaBundle.message("javadoc.generate.no.classes.in.selected.packages.error"));
}
Set<Module> modulesWithoutDescriptor = new HashSet<>(modules);
Map<Module, VirtualFile> moduleDescriptors = new HashMap<>();
boolean hasJavaModules = false;
for (VirtualFile source : sources) {
if (!PsiJavaModule.MODULE_INFO_FILE.equals(source.getName())) {
continue;
}
hasJavaModules = true;
Module module = ModuleUtilCore.findModuleForFile(source, myProject);
if (module != null) {
moduleDescriptors.put(module, source);
modulesWithoutDescriptor.remove(module);
}
}
if (hasJavaModules && !modulesWithoutDescriptor.isEmpty()) {
// So far we can't generate javadoc for each module independently as we have to merge the results into common files,View on GitHub (pinned to be881553f2)
Solutions
- Re-check the scope combobox in the Generate JavaDoc dialog — pick a package/scope that actually contains .java files.
- Mark Java directories as Sources Root (right-click | Mark Directory as | Sources Root) so they are traversable.
- For mixed-language projects, confirm the module really has Java sources; Kotlin-only scopes will always fail here.
Defensive patterns
Strategy: validation
Validate before calling
// Before generation, confirm the scope yields Java sources
Set<VirtualFile> javaSources = collectJavaSources(project, scope);
if (javaSources.isEmpty()) { notify("Selected scope contains no Java sources"); return; } Prevention
- Mark Java directories as Sources Root
- Double-check the scope/package selection in the Generate JavaDoc dialog
- Remember Kotlin-only scopes produce no Java sources
When it happens
Trigger: Invoking Tools | Generate JavaDoc with a scope selection (e.g. a custom scope or package) that matches no Java files, or when the project's Java directories are not marked as Sources Roots so the content iterator never yields them.
Common situations: Running generation from a view where the selected package contains only resources or Kotlin; newly opened projects whose source roots are unmarked; custom scopes with overly restrictive patterns; generated-code-only modules excluded from the scope.
Related errors
- IDEA cannot generate Javadoc as module-source-path cannot be
- module.paths.validation.source.root.belongs.to.another.module.error
- Cannot generate JavaDoc - no Java SDK is configured for the
- IDEA cannot generate Javadoc as modules {0} do not contain m
- Malformed exclusion, 'groupId:artifactName' format is expect
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/28b7f3c87f2e1f4d.
Report an issue: GitHub.