简体   繁体   中英

how do i exclude a source tree from a gradle javadoc task

I'm sure this is trivial, but can't find any examples out there to remove a source tree from the generated java doc. My source tree is

src/main/java/...
src/test/java/...
src/samples/java/...

I have tried two tasks, neither seem to work.

javadoc {
    exclude               "src/test/**"
    exclude               "src/samples/**"
}

task gendocs(type: Javadoc) {
    source = sourceSets.main.allJava
    classpath += configurations.compile
    exclude               "src/test/java/**/*"
}

Here's the complete file (updated to try Lance Java's suggestion), but no joy.

apply plugin: 'java'
apply plugin: 'distribution'
apply plugin: 'maven-publish'

group = 'com.ibm.watson.iot.sound'
version = '0.0.1'

description = 'IoT Sound project build configurations'

sourceSets.all { set ->
    def jarTask = task("${set.name}Jar", type: Jar) {
        baseName = baseName + "-$set.name"
        from set.output
    }
    artifacts { archives jarTask }
}

sourceSets {
    main {
        java {
            srcDir "src/main/java"
            srcDir "src/client/java"
            srcDir "src/test/java"  
        }
        resources {
            srcDir "src/main/java"
            srcDir "src/client/java"
            srcDir "src/test/java"  
        }
    }

    client {
        java {
            srcDir "src/client/java"
        }
        resources {
            srcDir "src/client/java"
        }
        compileClasspath += sourceSets.main.compileClasspath    
        compileClientJava {
            sourceCompatibility = "1.7"
            targetCompatibility = "1.7"
        }
    }
}


// Make so javadoc errors do not cause the gradle command to fail
if (JavaVersion.current().isJava8Compatible()) {
    allprojects {
      tasks.withType(Javadoc) {
        options.addStringOption('Xdoclint:none', '-quiet')
      }
    }
}

javadoc {
    source = sourceSets.main.allJava.matching {
        exclude 'src/test/**'
        exclude 'src/samples/**'
    }
}

test { 
    testLogging {
        events "PASSED", "STARTED", "FAILED", "SKIPPED"
    }
    exclude 'com/ibm/watson/iot/sound/*/**/*'
    include 'com/ibm/watson/iot/sound/*TestSuite*'
}

task release(type: Zip, dependsOn : [javadoc,mainJar, clientJar, publishToMavenLocal]) {
    description = 'Builds the release zip for this project'
            into ('caa') {
                from ('resources') {
                    include '*.properties'
                }
            }
            into('caa/lib')  {
                // from ('build/libs/IoT-Sound-0.0.1.jar')  
                from clientJar.outputs.files    
                from (configurations.compile)  
                from jar.outputs.files          
                from ('src/client/java/logback.xml')
                from ('caa.properties')
                from ('wpml.properties')
            }
            into('caa/bin') {
                from ('scripts') 
                fileMode 0755
            }
            into('caa/samples') {
                from ('src/samples/java') 
            }
            into ('caa/docs') {
                from ('build/docs') 
            }
}

println release.archiveName
println relativePath(release.destinationDir)
println relativePath(release.archivePath)

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
        api(MavenPublication) {
            artifactId 'IoT-Sound-Client' 
            artifact clientJar 
       }
    }
}

configurations {
    all*.exclude group: 'org.bytedeco', module: 'javacpp-presets' 
    all*.exclude group: 'com.github.fommil.netlib', module: 'all'
}

repositories {

     maven { url "https://repo.eclipse.org/content/repositories/paho-releases/" }
     maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
     maven { url "http://repo.maven.apache.org/maven2" }
}


dependencies {
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
    compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.2'
    compile group: 'org.mongodb', name: 'mongo-java-driver', version:'3.2.2'
    compile group: 'org.apache.commons', name: 'commons-csv', version:'1.2'
    compile 'com.google.code.gson:gson:2.3.1'
    compile group: 'log4j', name: 'log4j', version: '1.2.17'    // need by SII
    compile fileTree(dir: 'lib', include: '*.jar')
    compile group: 'org.apache.commons', name: 'commons-math', version:'2.1'
    compile group: 'org.apache.commons', name: 'commons-math3', version:'3.4.1'
    compile group: 'gov.sandia.foundry', name: 'cognitive-foundry', version:'3.4.3'
    compile group: 'tw.edu.ntu.csie', name: 'libsvm', version: '3.17' 
    compile group: 'junit', name: 'junit', version:'4.12'   
    compile group: 'org.deeplearning4j', name: 'deeplearning4j-core', version:'0.5.0'  
    compile group: 'org.nd4j', name: 'nd4j-native-platform', version:'0.5.0' 
}

Many things wrong with your script so will address them in a separate answer

  1. src/test/x should NOT be under sourceSets.main (it's already under sourceSets.test ). Putting test sources in the main sourceSet will mean that test classes end up being packed inside your jar!!
  2. java folders should NOT be under sourceSets.x.resources . Java folders should contain *.java files only. Any resources (eg *.xml and *.properties ) should live in src/x/resources folders. Putting java folders in your resources will mean your plain *.java files will also end up in the jar!!
  3. If you only want specific folders to be included by javadoc then don't start with sourceSets.main.allJava . Just add the specific folders you need as suggested by @Stanislav
  4. The exclude inside FileTree.matching { } is relative to the FileTree root. exclude 'src/test/**' and exclude 'src/samples/**' aren't valid at this point. Same goes for exclude inside javadoc . Take a look at the exclude under your test task. These are correctly root relative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM