我有一个包含多个android项目的工作区,如下所示:
所有项目都使用gradle进行编译。
我可以使用以下代码添加指令以在Android应用和lib上生成javadoc:
applicationVariants.all {...}
or
libraryVariants.all { variant ->
println variant
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
options.links("http://docs.oracle.com/javase/7/docs/api/");
options.linksOffline("http://d.android.com/reference", "${android.sdkDirectory}/docs/reference");
exclude '**/BuildConfig.java'
exclude '**/R.java'
}
}
我想要的是将此指令添加到根项目中build.gradle文件的所有子项目中。
我相信这会使用subprojects {}
指令,但我不知道配置过程后如何运行此指令中的代码,我不知道如何检测我的应用程序是否是库
答案 0 :(得分:2)
Indead,我成功地使用了subprojects {}
指令。
关键是使用afterEvaluate {}
,所以我可以使用android gradle插件添加的android属性。
以下是我结束的代码:
subprojects{
afterEvaluate { project ->
if(project.hasProperty('android')){
if(project.android.hasProperty('libraryVariants')) {
project.android.libraryVariants.all { variant ->
println variant
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${project.android.sdkDirectory}/platforms/${project.android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
options.links("http://docs.oracle.com/javase/7/docs/api/");
options.linksOffline("http://d.android.com/reference", "${project.android.sdkDirectory}/docs/reference");
exclude '** /BuildConfig.java'
exclude '** /R.java'
}
}
}
else if (project.android.hasProperty('applicationVariants')){
project.android.applicationVariants.all { variant ->
println variant
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${project.android.sdkDirectory}/platforms/${project.android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
options.links("http://docs.oracle.com/javase/7/docs/api/");
options.linksOffline("http://d.android.com/reference", "${project.android.sdkDirectory}/docs/reference");
exclude '** /BuildConfig.java'
exclude '** /R.java'
}
}
}
}
}
}