Dynamic javadoc groups

I need to be able to maintain a list of javadoc groups that would be unwieldy to do by hand.

I have a package naming scheme that indicates whether packages are (1) APIs, (2) SPIs or (3) private/internal. I want to use those as the basis for my javadoc groups. Unfortunately the “split” there comes at the end of the package names. For example: org.hibernate.stat org.hibernate.stat.spi org.hibernate.stat.internal

I assume I will need to iterate over each class/package and check the package name, but I am not sure how best to do that in Gradle. Something like this?:

subprojects.each{ subProject->
    subProject.sourceSets.main.java.each { javaFile ->
        ...
    }
}

Looks good except that you may need to defer the evaluation, for example by wrapping the code with gradle.projectsEvaluated {}.

Thanks Peter. A related question. Given a source set, is there a means to get the name of classes contained there? Or at least the relative .java file path (relative to the corresponding source dir)?

One option is to iterate over sourceSets.main.java with the visit() method:

...
subproject.sourceSets.main.java.visit { details ->
  if (details.directory) return
  def relativePath = details.relativePath.toString()
  ...
}