Skip to content

SpringModulithProcessor from apt rewrites javadoc.json if application modules in different gradle modules #1133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ajax-semenov-y opened this issue Mar 31, 2025 · 5 comments
Assignees
Labels
in: documentation support Documentation generation meta: waiting for feedback Waiting for feedback of the original reporter
Milestone

Comments

@ajax-semenov-y
Copy link

I have a multi-module Gradle project with application modules in different Gradle modules. I've added apt to gather Javadoc for documentation, and it runs separately for each module. However, each module overwrites the javadoc.json file content.

I'm uncertain about the best way to handle this. A solution that comes to mind is to generate a javadoc.json file in each module's build directory and then, when creating SpringModulithDocumentationSource, parse all build directories for javadoc.json files and consolidate them into one instance.

@odrotbohm
Copy link
Member

I am not a Gradle expert, but I'd assume the APT to be executed from the folder of the Gradle module, so that the individual files end up in the build folder of that very module?

@odrotbohm odrotbohm self-assigned this Apr 1, 2025
@odrotbohm odrotbohm added in: documentation support Documentation generation meta: waiting for feedback Waiting for feedback of the original reporter labels Apr 1, 2025
@ajax-semenov-y
Copy link
Author

ajax-semenov-y commented Apr 1, 2025

I have created a small reproduce for this issue: GitHub Repository. Please ensure you checkout the modulith-apt-demo branch.

Steps to reproduce:

  • Run ./gradlew clean assemble in root

Actual result:

  • The build/generated-spring-modulith/javadoc.json file contains only one record, which will be the ModuleA, ModuleB, or ModuleC class, depending on which Gradle task completed last.
  • The module-a/build/generated-spring-modulith/javadoc.json and module-b/build/generated-spring-modulith/javadoc.json are not exist.

As a result, some of the Java documentation is missing because, when creating an instance of SpringModulithDocumentationSource, only the generated-spring-modulith/javadoc.json file from the root build directory is considered.

Expected result:

  • The JavaDocs from all Gradle modules are aggregated, and the complete documentation is available.

P.S. I suspect that a multi-module Maven project may encounter the same issue, but I cannot confirm this.

odrotbohm added a commit that referenced this issue Apr 3, 2025
Gradle's APT handling seems to significantly differ from Maven's as the Java compilation runs from a completely different base folder than the actual project compiled. Even more so, for multi-module projects, the base folder is always the same, which causes APT output using Java's plain File API to override itself in a multi-module project.

I've tweaked the output folder detection to look up well-known APT parameters provided by either the Spring Boot plugin (org.springframework.boot.configurationprocessor.additionalMetadataLocations) or KAPT (for Kotlin-based projects, kapt.kotlin.generated) and derive the actual output folder from the values set for those. If neither of these is set, we fall back to the original local folder.
@ajax-semenov-y
Copy link
Author

ajax-semenov-y commented Apr 4, 2025

Sorry that I forgot to mention that it's important to run ./gradlew clean assemble from the console, not from IDEA. Due to some bug in IDEA, it does not call annotation processors in submodules when executed this way (at least in my version of IDEA).

@odrotbohm
Copy link
Member

Can you try the 1.4.0-SNAPSHOTS? Happy to backport the fix to the currently maintained branches if that helps.

@odrotbohm odrotbohm added this to the 1.4 RC1 milestone Apr 4, 2025
@ajax-semenov-y
Copy link
Author

Checked on 1.4.0-SNAPSHOTS - each Gradle module now has a corresponding /build/generated-spring-modulith/javadoc.json file, thanks for quick fix!

However, these files are not used by SpringModulithDocumentationSource because BuildSystemUtils.getTargetResource(METADATA_FILE), which is employed to create the SpringModulithDocumentationSource instance, points to the root. As a result, javadocs from the modules are not included in the SpringModulithDocumentationSource#metadata collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: documentation support Documentation generation meta: waiting for feedback Waiting for feedback of the original reporter
Projects
None yet
Development

No branches or pull requests

2 participants