tunguski / interfacer

Add interfaces to classes generated by other plugins
Apache License 2.0
12 stars 2 forks source link

allow multiple interfacePackages or simply scan recursively from a wildcarded package path #8

Open SingingBush opened 1 year ago

SingingBush commented 1 year ago

Hi, I've setup interfacer to process some generated java files that are output by the gradle-avro-plugin

plugins {
    id 'java-library'
    id 'maven-publish'
    id "com.github.davidmc24.gradle.plugin.avro-base" version "1.7.1"
    id "io.github.tunguski.interfacer" version "0.0.7"
}

...

tasks.register("avroInterfacer", pl.matsuo.interfacer.gradle.InterfacerTask) {
    dependsOn generate
    interfacePackage = 'com.company.schema.core'
    interfacesDirectory = file('src/main/java')
    scanDirectory = file("build/generated/java")
}

so far this is working fine but within my project I have interfaces in different packages based on areas of concern. It would be good if instead of having interfacePackage that I could either specify something like interfacePackages = 'com.company.schema.*' or perhaps interfacePackages = ['com.company.schema.core', 'com.company.schema.users', 'com.company.schema.products']

SingingBush commented 1 year ago

perhaps another option would be for the annotation to support full package path:

@java-interface("com.company.schema.users.EndUser")
tunguski commented 1 year ago

I am not sure I understand - what would be the difference between interfacePackages = 'com.company.schema.*' and interfacePackage = 'com.company.schema'? If you need recursive scan of interfaces in subpackages, then I believe it is done by default.

But if you need to explicitly list multiple packages, I think it may be possible through undocumented feature - https://github.com/tunguski/interfacer/blob/master/interfacer-core/src/main/java/pl/matsuo/interfacer/core/ClasspathInterfacesScanner.java#L36.

SingingBush commented 1 year ago

I'll give this another go then. When I was trying to use it a few days ago I seemed to need to specify the full package path to a single package where I had some interfaces and in the annotation just pit the interface name. I have a few other packages that I want to use interfaces for so I'll give interfacePackage = 'com.company.schema' a go and confirm if all ok.

I like being verbose though so if interfacePackage = 'com.company.schema.core,com.company.schema.users,com.company.schema.products' is already a working feature I'm happy.

Potentially this is just a case of making the documentation more clear that interfacePackage can be comma separated values.