-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathbuild.gradle
More file actions
141 lines (121 loc) · 4.54 KB
/
build.gradle
File metadata and controls
141 lines (121 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
// Core Gradle plugins
id "java-gradle-plugin"
id "jacoco"
// Third-party plugins
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.kotlinDokka)
alias(libs.plugins.pluginPortalPublish)
alias(libs.plugins.mavenPublish)
}
// To upload new plugin artifact Gradle Portal:
// > ./gradlew publishPlugins
//
// To upload new plugin artifact to Maven Central Repository:
// > ./gradlew publish --no-daemon --no-parallel
//
// To test the plugin:
// > ./gradlew clean test
version = VERSION_NAME
group = GROUP
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
compilerOptions {
jvmTarget = JvmTarget.JVM_17
}
}
jacocoTestReport {
reports {
xml.required = true
csv.required = false
}
}
mavenPublishing {
publishToMavenCentral()
signAllPublications()
}
gradlePlugin {
setWebsite(POM_URL)
setVcsUrl(POM_SCM_URL)
plugins {
rootCoverage {
id = 'nl.neotech.plugin.rootcoverage'
implementationClass = 'org.neotech.plugin.rootcoverage.RootCoveragePlugin'
displayName = 'Android-Root-Coverage-Plugin'
description = POM_DESCRIPTION
tags.set(['android', 'coverage', 'jacoco', 'code-coverage', 'coverage-report', 'aggregated-report'])
}
}
}
// Since version 1.0.0 com.gradle.plugin-publish creates it's own javadocs, these do not
// seem to support Kotlin and end-up empty. The plugin does not provide an easy way to
// use Dokka or modify it.
// The code below disables the default javadoc task, and modifies the javadocJar task to use dokka
// instead.
tasks.named('javadoc') {
enabled = false
}
tasks.register('javadocJar', Jar) {
archiveClassifier.set('javadoc')
dependsOn tasks.dokkaGeneratePublicationHtml
from tasks.dokkaGeneratePublicationHtml
}
test {
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
showStandardStreams true
}
}
dependencies {
compileOnly gradleApi()
implementation libs.androidGradlePlugin
// Without depending on the full Android Gradle Plugin, the test fixture is unable to locate the Android Gradle Plugin.
// Not sure why this is, but for now this is a quick fx to add it to the TestKit classpath.
testImplementation libs.androidGradlePlugin
testImplementation libs.bundles.jvmTest
testImplementation gradleTestKit()
testImplementation libs.mockk
testImplementation libs.jacksonYaml
testImplementation libs.jacksonKotlin
}
// Setup Jacoco for Gradle TestKit
pluginManager.withPlugin("jacoco") {
// Extracts the JaCoCo runtime jar from the configured JaCoCo Agent
def extractJacocoRuntimeTask = tasks.register("extractJacocoTestKitRuntime", Copy) {
from {
zipTree(project.configurations.getByName(JacocoPlugin.AGENT_CONFIGURATION_NAME).asPath).matching { include 'jacocoagent.jar' }.singleFile
}
into project.layout.buildDirectory.dir("testkit")
}
def javaTestTask = tasks.named(JavaPlugin.TEST_TASK_NAME)
def destinationFileProvider = javaTestTask.map {
(it.extensions.getByType(JacocoTaskExtension.class) as JacocoTaskExtension).destinationFile
}
// Generates a gradle.properties file that contains the correct JVM arguments to run with the extracted JaCoCo agent
def generateGradlePropertiesTask = tasks.register("generateJacocoTestKitGradleProperties", WriteProperties.class) {
it.group = "reporting"
it.description = "Generates testkit-gradle.properties file which can be read and added to a TestKit build as gradle.properties"
it.dependsOn(extractJacocoRuntimeTask)
it.outputFile = new File(buildDir, "testkit/${javaTestTask.name}/gradle.properties")
it.property("org.gradle.jvmargs", "\"-javaagent:${buildDir}/testkit/jacocoagent.jar=destfile=${destinationFileProvider.get()}\"")
}
// Make the generated gradle.properties file available on the test classpath as resource
dependencies.add(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, files(new File(buildDir, "testkit/${javaTestTask.name}")))
// "Fixes": https://github.com/gradle/gradle/issues/16603
def jacocoTestReport = tasks.named("jacocoTestReport")
jacocoTestReport.configure {
it.doFirst {
sleep(1000)
}
}
// Setup task dependencies
javaTestTask.configure {
it.dependsOn(generateGradlePropertiesTask)
it.finalizedBy(jacocoTestReport)
}
}