2017-09-01 104 views
2

我想從aar lib文件中生成javadoc,但是我的實際任務不工作,並且以錯誤結束。我有點失落,因爲有了gradle。如何用Gradle生成javadoc?

應該在哪裏生成javadoc?

android.libraryVariants.all { variant -> 

    // This part is for change AAR location 
    variant.outputs.each { output -> 
     def outputFile = output.outputFile 
     if (outputFile != null && outputFile.name.endsWith('.aar')) { 
      def fileName = "${archivesBaseName}-${version}.aar" 
      output.outputFile = new File("$rootProject.projectDir/build/generated-aar", fileName) 
     } 
    } 

    // Here generate tasks for variant to generate Javadocs 
    task "generate${variant.name.capitalize()}Javadoc"(type: Javadoc) { 
     description = "Generates javadoc for build $variant.name" 
     destinationDir = new File("$rootProject.projectDir/build/generated-javadoc", variant.baseName) 

     // add SDK classes 
     source = variant.javaCompiler.source 

     ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar" 
     classpath = files(variant.javaCompiler.classpath.files) + files(ext.androidJar) 

     ext.androidDoc = "${android.sdkDirectory}/docs/reference" 

     options.linksOffline("http://d.android.com/reference", ext.androidDoc) 
     options.links("http://docs.oracle.com/javase/7/docs/api/") 
     options.links("http://d.android.com/reference/") 

     exclude '*BuildConfig.java' 
     exclude '*R.java' 
     exclude '*impl*' 
     exclude '*tests*' 
    } 
} 
+0

也許你可以添加導致構建失敗的錯誤? – dpr

回答

4

如果你是以下標準項目結構,然後使用:

apply plugin: 'java' 

javadoc { 
    source = sourceSets.main.allJava 
    classpath = configurations.compile 
} 

如果沒有,那麼你需要指定包括關閉。添加封樣:

include 'path/to/directory/*' 

如果包括關閉不工作與SRCDIR指向模塊/ java目錄添加sourceSet關閉:

sourceSets { 
    build { 
     java.srcDir file('src/main/java') 

    } 
} 

且運行$gradle javadoc命令後。 然後檢查您的構建目錄中是否有包含所有javadoc的html文件。 注意:用您的根包路徑替換srcDir

+0

我已經使用android.library插件和maven插件。 –

+0

我嘗試'include **/*。java'但沒有結果 –