Skip to content
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

Does not work when used in a library #82

Open
lewimuchiri opened this issue Apr 22, 2024 · 2 comments
Open

Does not work when used in a library #82

lewimuchiri opened this issue Apr 22, 2024 · 2 comments

Comments

@lewimuchiri
Copy link

lewimuchiri commented Apr 22, 2024

Assuming you have a library my-library with the following dependencies:

dependencies {
    compileOnly("org.atteo.classindex:classindex:3.4") // also tried implementation(..). Didn't work
    annotationProcessor("org.atteo.classindex:classindex:3.4")
}

And a custom annotation:

@Retention( RetentionPolicy.RUNTIME )
@IndexAnnotated
public @interface MyCustomAnnotation {
}

And a method in the library to get all classes with that annotation:

    public void getClassesWithAnnotation() {
        Iterable<Class<?>> klasses = ClassIndex.getAnnotated(MyCustomAnnotation.class);
        ...
    }

And then the library is imported into another Java project as follows:

    implementation("app.libs.io:my-library:2.0.0.8-SNAPSHOT") 

Then the Java Project has a class with that annotation:

@MyCustomAnnotation
public class TestClass {
}

When the Java project calls the getClassesWithAnnotation() from the library, it gets an empty list, showing that the classes in the Java project were not scanned.

@sentinelt
Copy link
Member

I'm not a Gradle user myself, but I guess this is due to Gradle not doing a proper annotation processor discovery anymore. You probably need to add an additional annotationProcessor("app.libs.io:my-library:2.0.0.8-SNAPSHOT") dependency in the projects that are using your library.

@lewimuchiri
Copy link
Author

Thanks. Will attempt tomorrow and give feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants