Excluding generated source from javadoc

(steve) #1

How do I get generated sources excluded from javadoc task as sources? I tried the following, but it did not work:

task aggregateJavadocs(type: Javadoc) {
    exclude "**/generated-src/**"

Javadoc sources and generated source
(Peter Niederwieser) #2

Not sure what the problem is. The syntax is correct. We use this in the Gradle build and it seems to work fine:

task javadoc(type: Javadoc) {
  exclude '**/internal/**'

(steve) #3

Could it be timing? I have a bit of a unique javadoc task:

task aggregateJavadocs(type: Javadoc) {
    // exclude any generated sources
    exclude "**/generated-src/**"
      // process each project, building up:
    1) appropriate sources
    2) classpath
    3) the package list for groups
    Set<String> apiPackages = new HashSet<String>()
    Set<String> spiPackages = new HashSet<String>()
    Set<String> internalPackages = new HashSet<String>()
    parent.subprojects.each{ Project subProject->
        // skip certain sub-projects
        if ( ! ['release','documentation'].contains( subProject.name ) ) {
            subProject.sourceSets.each { SourceSet sourceSet ->
                // skip certain source sets
                if ( ! ['test','matrix'].contains( sourceSet.name ) ) {
                    source sourceSet.java
                      if( classpath ) {
                        classpath += sourceSet.classes + sourceSet.compileClasspath
                    else {
                        classpath = sourceSet.classes + sourceSet.compileClasspath
                      sourceSet.java.each { javaFile ->
                        final String packageName = determinePackageName( sourceSet.java, javaFile );
                        if ( packageName.endsWith( ".internal" ) || packageName.contains( ".internal." ) ) {
                            internalPackages.add( packageName );
                        else if ( packageName.endsWith( ".spi" ) || packageName.contains( ".spi." ) ) {
                            spiPackages.add( packageName );
                        else if ( packageName.startsWith( "org.hibernate.testing" ) ) {
                            // do nothing as testing support is already handled...
                        else {
                            apiPackages.add( packageName );
      // apply standard config
    description = "Build the aggregated JavaDocs for all modules"
    configure( options ) {
        group( 'API', apiPackages.asList() )
        group( 'SPI', spiPackages.asList() )
        group( 'Internal', internalPackages.asList() )
        group ( 'Testing Support', ['org.hibernate.testing*'] )

Those closures seem to fire right off the bat.

(Peter Niederwieser) #4

Did you paste this twice?

(steve) #5

I dont think so

(steve) #6

I’ll filter out the unimportant stuff and see if that helps…

(Peter Niederwieser) #7

task aggregrateJavadocs appears twice in the code snippet. Is this highlighting gone (very) wrong?

(steve) #8

The markup parser did not like something in the original paste…

(Peter Niederwieser) #9

Can you send me the original snippet via email so that we can reproduce the parser problem?

(Peter Niederwieser) #10

There shouldn’t be a timing problem with exclude, but there will be one with the groups. One solution is to do the whole javadoc task configuration in a gradle.projectsEvaluated {}.

(steve) #11

groups actually works

(steve) #12

I really only want it to execute that stuff when the task executes. Is that possible?

(steve) #13

The build file can be found here in case you wanted to verify: https://github.com/hibernate/hibernate-core/blob/master/release/release.gradle

Btw, I did try wrapping all that ‘parent.subprojects.each’ processing within a gradle.projectsEvaluated {} because you had mentioned that on another post, but that led to some really strange errors.

(Peter Niederwieser) #14

Currently the only way to do this is gradle.taskGraph.whenReady { if (it.hasTask(":foo")) { … } }. However you can abstract that into your own method. Note that you can’t add tasks or task dependencies at this point.

(Peter Niederwieser) #15

You are probably lucky. If someone adds a source set after that javadoc configuration has run (e.g. by applying the “java” plugin in a subproject’s build script), the source set won’t be picked up by your code. Unless you have put special measures in place like subprojects { rootProject.evaluationDependsOn(it) }.

(Peter Niederwieser) #16

Including the configure(options) { … } part?

(steve) #17

No, i dont think so. I think just the closure block

(Peter Niederwieser) #18

That won’t work because then you have a delayed computation whose results are used eagerly (i.e. before they have been fully computed).

(steve) #19

The root project has dependsOnChildren() The project being executed is the final child; it depends on all the other children, but none of them depend on it.

Not sure if its really luck :wink:

(steve) #20

I can try again to see the outcome… but do you really think that will have any bearing on making the exclusion actually work?