-
Notifications
You must be signed in to change notification settings - Fork 30
/
build.gradle
163 lines (143 loc) · 4.69 KB
/
build.gradle
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.android.lint)
id("java-gradle-plugin")
alias(libs.plugins.publish)
alias(libs.plugins.dokka)
alias(libs.plugins.spotless)
}
gradlePlugin {
plugins {
licensee {
id = "app.cash.licensee"
displayName = "Licensee"
description = "Gradle plugin which validates the licenses of your dependency graph match what you expect"
implementationClass = "app.cash.licensee.LicenseePlugin"
}
}
}
tasks.named("validatePlugins") {
enableStricterValidation = true
}
dependencies {
compileOnly libs.androidGradleApi
compileOnly libs.kotlinGradlePlugin
implementation libs.kotlinx.serialization
implementation libs.maven.modelBuilder
testImplementation libs.junit
testImplementation libs.assertk
testImplementation libs.testParameterInjector
testImplementation gradleTestKit()
lintChecks libs.androidx.gradlePluginLints
}
kotlin {
jvmToolchain(11)
target {
compilations.configureEach {
// Ensure compatibility with old Gradle versions. Keep in sync with LicenseePlugin.kt.
compilerOptions.options.apiVersion.set(KotlinVersion.KOTLIN_1_8)
}
}
}
tasks.named("test") {
dependsOn(':publishAllPublicationsToTestingRepository')
systemProperty('licenseeVersion', VERSION_NAME)
systemProperty('generatedSpdxFile', file("build/generated/spdx/app/cash/licensee/licensesSpdx.kt").path)
systemProperty('line.separator', '\n')
testLogging {
if (System.getenv("CI") == "true") {
events = ["failed", "skipped", "passed"]
}
exceptionFormat "full"
}
// AGP 8+ requires JVM 17+.
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(20)
}
// Required to test configuration cache in tests when using withDebug()
// https://github.com/gradle/gradle/issues/22765#issuecomment-1339427241
jvmArgs(
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.util.concurrent.atomic=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens",
"java.base/java.net=ALL-UNNAMED",
)
}
def fixtures = file('src/test/fixtures')
def minimalJarBase64 = 'UEsFBgAAAAAAAAAAAAAAAAAAAAAAAA=='
tasks.register('writeFixtureJars') { task ->
task.doFirst {
fixtures.eachFileRecurse { File file ->
if (file.toString().contains('/repo/') && file.name.endsWith('.jar')) {
file.bytes = minimalJarBase64.decodeBase64()
}
}
}
}
def checkFixtureJars = tasks.register('checkFixtureJars') { task ->
task.doFirst {
fixtures.eachFileRecurse { File file ->
if (file.toString().contains('/repo/') && file.name.endsWith('.jar')) {
def fileBase64 = file.readBytes().encodeBase64().toString()
if (fileBase64 != minimalJarBase64) {
throw new RuntimeException(
"Expected '$minimalJarBase64' but was '$fileBase64'\n\n" +
"Invoke 'writeFixtureJars' task to fix.")
}
}
}
}
}
tasks.named('check') { check ->
check.dependsOn(checkFixtureJars)
}
Directory jsonFolder = layout.projectDirectory.dir("src/main/resources/app/cash/licensee")
RegularFile jsonFile = jsonFolder.file("licenses.json")
tasks.register("downloadLicensesJson", Copy) {
group = "generatespdx"
from(resources.text.fromUri("https://spdx.org/licenses/licenses.json").asFile()) {
rename {
jsonFile.asFile.name
}
}
into(jsonFolder)
doLast {
def destFile = jsonFile.asFile
def json = new JsonSlurper().parse(destFile)
json.licenses = json.licenses.sort { a, b -> a.licenseId <=> b.licenseId }
destFile.text = JsonOutput.prettyPrint(JsonOutput.toJson(json))
}
}
TaskProvider<app.cash.licensee.GenerateSpdxIdTask> generateSpdx = tasks.register('generateSpdx', app.cash.licensee.GenerateSpdxIdTask) {
// Do not wire the output from writeSortedSpdx here to split downloading the remote file and code gen.
inputJson.set(jsonFile)
}
sourceSets.main.kotlin.srcDir(generateSpdx)
publishing {
repositories {
maven {
name = "testing"
url = "${rootProject.projectDir}/build/localMaven"
}
}
}
spotless {
kotlin {
target('**/*.kt')
targetExclude("**/src/test/test-build-logic/build/**", "**/generated-sources/**")
ktlint(libs.ktlint.get().version).editorConfigOverride([
'ktlint_standard_filename': 'disabled',
// Making something an expression body should be a choice around readability.
'ktlint_standard_function-expression-body': 'disabled',
])
licenseHeaderFile(rootProject.file('gradle/license-header.txt'))
}
}