我正在为API构建JavaDoc,其中API中的类依赖于R.java.我想构建引用缺少的R.java文件的Javadoc w/o符号错误,即使我设置failOnError false
构建成功但我们的Jenkins作业会在成功构建中发生错误时将构建报告为失败.下面的任务将成功创建javadocs,但会在构建过程中报告与未找到R.java相关的错误.
android.libraryVariants.all { variant -> def name = variant.name.capitalize() task("generate${name}Doclava", type: Javadoc) { description "Generates Javadoc for $variant.name." source = variant.javaCompile.source title = null // use android.bootClasspath instead of building our own path to android jar //ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar" // hardcoded path to generated R.java file to avoid javadoc compile issues ext.R = "build/generated/source/r/minSDK15/release" classpath += project.files(android.sourceSets.main.java.srcDirs, variant.javaCompile.classpath.files, android.bootClasspath) destinationDir = file("${project.docsDir}/${name}/doclava") options { docletpath = configurations.jaxDoclet.files.asType(List) doclet "com.google.doclava.Doclava" bootClasspath new File(System.getenv('JAVA_HOME') + "/jre/lib/rt.jar") addStringOption "XDignore.symbol.file", "-quiet" addStringOption "hdf project.name", "${project.name}" addStringOption "federate android", "http://d.android.com/reference" addStringOption "federationxml android", "http://doclava.googlecode.com/svn/static/api/android-10.xml" addStringOption "federate JDK", "http://download.oracle.com/javase/6/docs/api/index.html?" addStringOption "federationxml JDK", "http://doclava.googlecode.com/svn/static/api/openjdk-6.xml" addStringOption "templatedir", "${project.docsDir}/${name}/doclava/templates" addStringOption "apixml", "${project.docsDir}/${name}/doclava/api-${project.version}.xml" addStringOption "since doclava/since/api-1.0.0.xml", "1.0.0" addStringOption "apiversion", "${project.version}" failOnError false } // exclude generated files exclude '**/BuildConfig.java' exclude '**/R.java' // exclude internal packages exclude '**/internal/**' options.addStringOption "apixml", "${project.docsDir}/${name}/doclava/api-${project.version}.xml" } }
我试过的一些事情:
硬编码生成的R.java文件的路径并添加到类路径.
classpath += project.files(android.sourceSets.main.java.srcDirs, variant.javaCompile.classpath.files, android.bootClasspath, ext.R)
这成功地删除了错误,因此构建成功,但生成的javadoc在javadoc中有到R.*.class的空链接.
exclude '**/R.java'
从排除列表中删除该行,同时不包括类路径中R.java的路径.
这成功地删除了错误并且构建成功,但生成的javadoc具有到R.*.class文件的链接.
似乎exclude
语句是从类路径而不是javadoc中排除的.任何深入了解如何生成类依赖于R.java但在javadoc输出中不包含R.java的javadoc将深深体会到.