forked from square/anvil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
141 lines (120 loc) · 4.53 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
import com.squareup.anvil.benchmark.CreateBenchmarkProjectTask
import org.gradle.api.internal.project.DefaultProject
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
dependencies {
classpath libs.mavenPublishRaw
classpath("com.squareup.anvil:gradle-plugin:${findProperty("VERSION_NAME")}",)
}
}
plugins {
alias(libs.plugins.agp.application) apply false
alias(libs.plugins.agp.library) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.kotlin.dokka) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.gradlePublish) apply false
alias(libs.plugins.ktlint) apply false
}
boolean isCi = (System.getenv('CI') ?: 'false').toBoolean()
String kotlinVersion = libs.versions.kotlin.get()
ext {
ci = isCi
fullTestRun = libs.versions.config.fullTestRun.get().toBoolean()
warningsAsErrors = isCi
}
println "Versions: " + [
"Kotlin": kotlinVersion,
"Gradle": gradle.gradleVersion,
"Full test run": ext.fullTestRun,
]
boolean configureOnDemandEnabled = getProperty("org.gradle.configureondemand", "false").toBoolean()
subprojects {
if (buildFile.exists()) {
apply plugin: 'org.jlleitschuh.gradle.ktlint'
ktlint {
version = libs.versions.ktlint.get()
verbose = true
}
}
tasks.withType(Test).configureEach {
testLogging {
events 'passed', 'failed', 'skipped', 'standardOut', 'standardError'
exceptionFormat 'FULL'
showCauses true
showExceptions true
showStackTraces true
showStandardStreams true
}
}
// Dynamically configure JVM targets because Dagger compiler always uses the java 11 @Generated
// annotation regardless of release target
boolean isIntegrationTestOrSample = project.path.startsWith(":integration-test") || project.path.startsWith(":sample")
pluginManager.withPlugin("java") {
// Use JDK 11 but target Java 8 for maximum compatibility.
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
tasks.withType(JavaCompile).configureEach {
if (isIntegrationTestOrSample) {
options.release.set(11)
} else {
options.release.set(8)
}
}
}
tasks.withType(KotlinCompile).configureEach {
compilerOptions {
if (isIntegrationTestOrSample) {
jvmTarget.set(JvmTarget.JVM_11)
} else {
jvmTarget.set(JvmTarget.JVM_1_8)
}
allWarningsAsErrors.set(warningsAsErrors)
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
boolean optInExperimental = project.name != "annotations"
&& project.name != "annotations-optional"
&& project.name != "scopes"
&& project.name != "dagger-factories-only"
if (optInExperimental) {
freeCompilerArgs.add("-opt-in=com.squareup.anvil.annotations.ExperimentalAnvilApi")
}
}
}
configurations.configureEach {
resolutionStrategy.dependencySubstitution {
substitute module("com.squareup.anvil:annotations") using project(':annotations')
substitute module("com.squareup.anvil:annotations-optional") using project(':annotations-optional')
substitute module("com.squareup.anvil:compiler") using project(':compiler')
substitute module("com.squareup.anvil:compiler-api") using project(':compiler-api')
substitute module("com.squareup.anvil:compiler-utils") using project(':compiler-utils')
}
resolutionStrategy {
force libs.kotlin.metadata
}
}
// We disable configure on demand in the local gradle.properties, but you can override this flag
// either in the CLI command or in ~/.gradle/gradle.properties. We really need to disable
// configure on demand in order to support the dependency substitution feature above. As a
// workaround force the evaluation of subprojects.
//
// The other option would be to stop the build if we detect configure on the demand, but some
// folks (including myself 🙃) set the flag globally in the Gradle home dir. The workaround
// is good enough for now.
if (configureOnDemandEnabled) {
(it as DefaultProject).evaluate()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
def getProperty(String name, String defaultValue) {
return project.hasProperty(name) ? project.getProperty(name) : defaultValue
}
// Register the task that can create the benchmark project.
tasks.register("createBenchmarkProject", CreateBenchmarkProjectTask)