Skip to content

Allow annotation processors for tests#1770

Closed
aggmegalou wants to merge 1 commit intospring-io:mainfrom
aggmegalou:gh-1380-annotation-processor-for-tests
Closed

Allow annotation processors for tests#1770
aggmegalou wants to merge 1 commit intospring-io:mainfrom
aggmegalou:gh-1380-annotation-processor-for-tests

Conversation

@aggmegalou
Copy link
Copy Markdown

Add opt-in support for annotation processor dependencies (e.g. Lombok) to be available for test compilation when using Gradle. When metadata sets annotationProcessorForTests: true, the dependency is added to both annotationProcessor and testAnnotationProcessor configurations.

  • Add annotationProcessorForTests flag to Dependency metadata
  • Add TEST_ANNOTATION_PROCESSOR scope to DependencyScope
  • Map scope in GradleBuildWriter and MavenBuildWriter
  • Add testCompileOnly.extendsFrom(testAnnotationProcessor) in Gradle customizer
  • Resolve test annotation processor dependency in DefaultProjectRequestToDescriptionConverter
  • Add MetadataBuildItemMapper.toDependency overload with scope override
  • Add tests and BuildComplianceTests for end-to-end verification

Closes gh-1380

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 19, 2026
Add opt-in support for annotation processor dependencies (e.g. Lombok) to be
available for test compilation when using Gradle. When metadata sets
annotationProcessorForTests: true, the dependency is added to both
annotationProcessor and testAnnotationProcessor configurations.

- Add annotationProcessorForTests flag to Dependency metadata
- Add TEST_ANNOTATION_PROCESSOR scope to DependencyScope
- Map scope in GradleBuildWriter and MavenBuildWriter
- Add testCompileOnly.extendsFrom(testAnnotationProcessor) in Gradle customizer
- Resolve test annotation processor dependency in DefaultProjectRequestToDescriptionConverter
- Add MetadataBuildItemMapper.toDependency overload with scope override
- Add tests and BuildComplianceTests for end-to-end verification

Closes spring-iogh-1380

Signed-off-by: Aggeliki <aggmegalou@gmail.com>
@aggmegalou aggmegalou force-pushed the gh-1380-annotation-processor-for-tests branch from ce88ab4 to cbbab4f Compare March 19, 2026 22:05
@mhalbritter mhalbritter self-assigned this Mar 27, 2026
@mhalbritter
Copy link
Copy Markdown
Contributor

Hey, thanks for the PR. After looking at it and the current arrangement, I think we have more refactoring to do, which is out of scope for this PR.

  • I don't like the configuration inheritance between annotation processors and compile scope for Gradle. For dependencies which are both an annotation processor and a library, it'd be better to add them as a annotation processor and as a "normal" dependency. I've already added testCompileOnly support in Add support for Gradle's testCompileOnly dependencies #1777. This also affects Annotation processors are added to compileOnly and annotationProcessor but we configure compileOnly to extend annotationProcessor #1379.
  • Annotation processors are only applied to main sources in Gradle, but on Maven they are applied to both main and test sources
  • Test annotation processor support is missing right now. If we add it, I think we should change the behavior: If an annotation processor is added, it's configured as annotationProcessor in Gradle and as an annotation processor ONLY for the main sources in maven. If a test annotation processor is added, it's configured as a testAnnotationProcessor and ONLY for the test sources in Maven.

I'll open separate issues for this and close the PR. Thanks anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow annotation processors to be made available to tests when using Gradle

3 participants