Excluding generated source from javadoc

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/**"
}

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/**'
}

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.

Did you paste this twice?

I dont think so

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

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

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

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

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 {}.

groups actually works

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

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.

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.

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) }.

Including the configure(options) { … } part?

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

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

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:

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