在java项目中很简单,gradle的示例文件夹中有两个实例。但是当我尝试在android项目中这样做时,出现了很多问题。
我无法添加
{apply plugin: 'java'}
和
test {
jacoco{
excludes = ['org/bla/**']
includes = ['com/bla/**']
append = false
}
}
和android插件有些冲突,test属于java插件,不知道怎么办。我可以构建、checkstyle、pmd、findbugs 和测试,但是 jacoco 报告。
我的gradle文件如下:
//Import android test dependencies
import com.android.build.gradle.api.TestVariant
//Load classpath and define the repository.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
//Sub project,we can add a lot of sub project here.
project('TVEAndroid')
{
//Load plugins
apply plugin: 'android'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'pmd'
//This is different with the one above,the previous one is just for load classpath,this one is for the real build.
repositories {
mavenCentral()
}
//Load dependencies,We will use nesux to hold the repositories in the future,so it will be changed.
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
//Jacoco plugin information declaration,but jacoco didn't work here,but it works in the java project with the same configuration.
jacoco {
toolVersion = "0.6.2.201302030002"
reportsDir = file("$buildDir/customJacocoReportDir")
}
//Define android build information
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
//Set the build path,the root folder
instrumentTest.setRoot('../TVEAndroidTest')
//Set the code and resuource path for build
instrumentTest {
java { srcDirs = [
'../TVEAndroidTest/src/'
] }
res.srcDirs = ['res']
assets.srcDirs = [
'../TVEAndroidTest/assets'
]
resources.srcDirs = [
'../TVEAndroidTest/src'
]
}
//Define the package name for build
defaultConfig {
testPackageName "com.accedo.android.tve.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpFile = file("$buildDir/jacoco/classpathdumps")
}
//PMD task
task pmd(type: Pmd) {
ruleSetFiles = files('../config/quality/pmd/pmd-ruleset.xml')
ruleSets = ["basic", "braces", "strings"]
source = android.sourceSets.main.java.srcDirs
}
//CheckStyle task
task checkstyle(type: Checkstyle) {
configFile file('../config/quality/checkstyle/checkstyle.xml')
source android.sourceSets.main.java.srcDirs
include '**/*.java'
exclude '**/gen/**'
classpath = files( project.configurations.compile.asPath )
}
//Findbugs task
task findbugs(type: FindBugs) {
excludeFilter file('../config/quality/findbugs/findbugs-filter.xml')
classes = fileTree('build/classes/debug')
source = android.sourceSets.main.java.srcDirs
classpath = files( project.configurations.compile.asPath )
reports {
xml {
destination "build/reports/findbugs/findbugs.xml"
}
}
effort = 'max'
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination "${buildDir}/jacocoHtml"
}
}
}
当前的问题是“找不到方法 jacocoTestReport() ...balabala”
任何建议将不胜感激!