Include annotation-loaded source files during test run

How can I get a test run to include source files that are loaded via annotations, but not imported?

For example, I have a file:


@AutoLoaded class SomeClass {}

and then when I run a test that doesn’t import explicity, but tries to load it via AutoLoaded.class annotation. it isnt available.

Any ideas how I can do this?

I don’t fully understand what you are trying to achieve, but it likely is a matter of how the test tries to load the annotated class, and whether it gets this right. I don’t see anything Gradle specific about this. Also I don’t think that the presence or absence of an import plays a role here, as a Java import is just a namespace thing, and doesn’t carry any other semantics.

I am testing a component that loads providers using annotations via AnnotationDB: The providers are in the “main” sourceSet, but are not directly referenced as explicit imports.

It finds the annotated providers properly when run from a main class from the “main” sourceSet, but doesn’t find any class files when run from a junit test in the “test” sourceSet.

What I thought was happening was that the test gradle task would only include classes on the classpath that were directly referenced from the junit test and dependencies.

Does this make sense, or should the same classes be available between the build and test task?