I left the contents created when I tried it in the following repository mitsuya-saida/clover-sample
| Dependent | License | 
|---|---|
| clover | Apache 2.0 license | 
| bmuschko/gradle-clover-plugin | Apache 2.0 license | 
Add gradle-clover-plugin to dependencies in buildscript as below
buildscript {
	dependencies {
		classpath 'com.bmuschko:gradle-clover-plugin:2.1.3'
	}
}
Addition of settings to apply plugin
apply plugin: 'com.bmuschko.clover'
Added clover to dependencies
dependencies {
	clover 'org.openclover:clover:4.2.0'
}
Describe clover settings
clover {
	report {
		html = true
	}
}
The build.gradle finally completed by the project made with Spring boot is as follows
buildscript {
	ext {
		springBootVersion = '1.5.8.RELEASE'
	}
	repositories {
		mavenCentral()
	}
	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
		classpath 'com.bmuschko:gradle-clover-plugin:2.1.3'
	}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.bmuschko.clover'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
	mavenCentral()
}
clover {
	report {
		html = true
		filter = 'main'
	}
}
dependencies {
	compile('org.springframework.boot:spring-boot-starter-web')
	compileOnly('org.projectlombok:lombok')
	testCompile('org.springframework.boot:spring-boot-starter-test')
	clover 'org.openclover:clover:4.2.0'
}
Please
The test is executed by the following command and the coverage file is output.
$ gradle clean cloverGenerateReport
Since the html of the report is generated in the build result, look at it with a browser In the case of this project, it is located in the following path
clover-sample/build/reports/clover/index.html
Looking at the browser, it looks like this

The available commands are as follows
| Command | Usage | 
|---|---|
| cloverGenerateReport | Run test and output coverage | 
| cloverAggregateReports | Aggregate test execution results for projects with multiple modules (I'm not sure because I've never used it) | 
Try excluding the main function, getters, and setters from coverage
Output coverage by writing the following in the clover settings
clover {
	contexts {
		method {
			name = 'main'
			regexp = 'public static void main\\(String\\[\\] args\\).*'
		}
	}
	report {
		html = true
		filter = 'main,property'
	}
}

Recommended Posts