Skip to content

Commit 591f7cb

Browse files
committed
misc build-logic cleanup
1 parent 1b790e2 commit 591f7cb

66 files changed

Lines changed: 260 additions & 300 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build-logic/build.gradle.kts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ buildscript {
2020
}
2121
}
2222

23-
// `alias(libs.______)` inside the plugins block throws a false positive warning
24-
// https://youtrack.jetbrains.com/issue/KTIJ-19369
25-
// There's also an IntelliJ plugin to disable this warning globally:
26-
// https://plugins.jetbrains.com/plugin/18949-gradle-libs-error-suppressor
2723
@Suppress("DSL_SCOPE_VIOLATION")
2824
plugins {
2925
base
3026
alias(libs.plugins.ktlint)
27+
alias(libs.plugins.dependencyAnalysis)
28+
alias(libs.plugins.moduleCheck)
29+
}
30+
31+
moduleCheck {
32+
checks {
33+
sortDependencies = true
34+
}
3135
}
3236

3337
allprojects {
@@ -50,6 +54,20 @@ allprojects {
5054
)
5155
}
5256
}
57+
58+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
59+
kotlinOptions {
60+
61+
languageVersion = "1.6"
62+
apiVersion = "1.6"
63+
64+
jvmTarget = "11"
65+
66+
freeCompilerArgs = freeCompilerArgs + listOf(
67+
"-opt-in=kotlin.RequiresOptIn"
68+
)
69+
}
70+
}
5371
}
5472

5573
tasks.withType<org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask> rootTask@{

build-logic/mcbuild/build.gradle.kts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
* limitations under the License.
1414
*/
1515

16-
// `alias(libs.______)` inside the plugins block throws a false positive warning
17-
// https://youtrack.jetbrains.com/issue/KTIJ-19369
18-
// There's also an IntelliJ plugin to disable this warning globally:
19-
// https://plugins.jetbrains.com/plugin/18949-gradle-libs-error-suppressor
2016
@Suppress("DSL_SCOPE_VIOLATION")
2117
plugins {
2218
`kotlin-dsl`
@@ -25,11 +21,12 @@ plugins {
2521
alias(libs.plugins.google.ksp)
2622
}
2723

28-
val kotlinVersion = libs.versions.kotlin.get()
29-
3024
dependencies {
3125

26+
api(libs.square.moshi)
27+
3228
compileOnly(gradleApi())
29+
3330
compileOnly(libs.kotlin.gradle.plug)
3431

3532
implementation(libs.benManes.versions)
@@ -39,32 +36,13 @@ dependencies {
3936
implementation(libs.google.dagger.api)
4037
implementation(libs.google.ksp)
4138
implementation(libs.kotlin.compiler)
39+
implementation(libs.kotlin.gradle.plug)
4240
implementation(libs.kotlinx.knit)
4341
implementation(libs.ktlint.gradle)
4442
implementation(libs.scabbard)
4543
implementation(libs.square.anvil.gradle)
46-
implementation(libs.square.moshi)
44+
implementation(libs.square.kotlinPoet)
4745
implementation(libs.vanniktech.publish)
4846

4947
ksp(libs.square.moshi.codegen)
5048
}
51-
52-
java {
53-
// This is different from the Kotlin jvm target.
54-
@Suppress("MagicNumber")
55-
toolchain.languageVersion.set(JavaLanguageVersion.of(11))
56-
}
57-
58-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
59-
kotlinOptions {
60-
61-
languageVersion = "1.5"
62-
apiVersion = "1.5"
63-
64-
jvmTarget = "11"
65-
66-
freeCompilerArgs = freeCompilerArgs + listOf(
67-
"-opt-in=kotlin.RequiresOptIn"
68-
)
69-
}
70-
}

build-logic/mcbuild/src/main/kotlin/mcbuild.dokka.gradle.kts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import modulecheck.builds.ModuleCheckBuildExtension
17-
import org.gradle.kotlin.dsl.findByType
16+
import modulecheck.builds.ArtifactIdExtension
1817
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
1918
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2019
import org.jlleitschuh.gradle.ktlint.tasks.KtLintCheckTask
@@ -24,9 +23,8 @@ plugins {
2423
id("org.jetbrains.dokka")
2524
}
2625

27-
tasks
28-
.withType<AbstractDokkaLeafTask>()
29-
.all {
26+
tasks.withType<AbstractDokkaLeafTask>()
27+
.configureEach {
3028

3129
// Dokka doesn't support configuration caching
3230
notCompatibleWithConfigurationCache("Dokka doesn't support configuration caching")
@@ -39,7 +37,7 @@ tasks
3937
// The default moduleName for each module in the module list is its unqualified "name",
4038
// meaning the list would be full of "api", "impl", etc. Instead, use the module's maven
4139
// artifact ID, if it has one, or default to its full Gradle path for internal modules.
42-
val fullModuleName = extensions.findByType<ModuleCheckBuildExtension>()?.artifactId
40+
val fullModuleName = extensions.findByType<ArtifactIdExtension>()?.artifactId
4341
?: project.path.removePrefix(":")
4442
moduleName.set(fullModuleName)
4543

build-logic/mcbuild/src/main/kotlin/mcbuild.gradle.kts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
@file:Suppress("SpellCheckingInspection", "VariableNaming")
17-
18-
import modulecheck.builds.ArtifactIdListener
19-
import modulecheck.builds.DIListener
20-
import modulecheck.builds.KspListener
2116
import modulecheck.builds.ModuleCheckBuildExtension
22-
import modulecheck.builds.applyAnvil
23-
import modulecheck.builds.applyDagger
24-
import modulecheck.builds.applyKsp
25-
import modulecheck.builds.configurePublishing
2617
import modulecheck.builds.libsCatalog
2718

2819
plugins {
@@ -34,31 +25,17 @@ plugins {
3425
id("mcbuild.kotlin")
3526
id("mcbuild.ktlint")
3627
id("mcbuild.test")
37-
}
38-
39-
val settings = extensions.create<ModuleCheckBuildExtension>(
40-
"mcbuild",
41-
ArtifactIdListener { onNewArtifactId(it) },
42-
DIListener { anvil, dagger ->
43-
applyAnvil(anvil = anvil, dagger = dagger)
44-
applyDagger(anvil = anvil, dagger = dagger)
45-
},
46-
KspListener { onKspToggled(it) }
47-
)
4828

49-
fun onNewArtifactId(artifactId: String) {
50-
project.configurePublishing(artifactId)
29+
id("com.google.devtools.ksp") apply false
5130
}
5231

53-
fun onKspToggled(useKsp: Boolean) {
54-
project.applyKsp(useKsp)
55-
}
32+
val settings = extensions.create<ModuleCheckBuildExtension>("mcbuild")
5633

57-
@Suppress("UnstableApiUsage")
5834
val kotlinVersion = project.libsCatalog
5935
.findVersion("kotlin")
6036
.get()
6137
.requiredVersion
38+
6239
configurations.all {
6340
resolutionStrategy {
6441
eachDependency {

build-logic/mcbuild/src/main/kotlin/mcbuild.kotlin.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>()
2222
kotlinOptions {
2323
allWarningsAsErrors = false
2424

25-
val kotlinMajor = "1.5"
25+
val kotlinMajor = "1.6"
2626

2727
languageVersion = kotlinMajor
2828
apiVersion = kotlinMajor

build-logic/mcbuild/src/main/kotlin/mcbuild.ktlint.gradle.kts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ plugins {
2222
}
2323

2424
extensions.configure(KtlintExtension::class.java) {
25+
val libVersion = libsCatalog.version("ktlint-lib").requiredVersion
26+
version.set(libVersion)
2527
debug.set(false)
26-
version.set(libsCatalog.version("ktlint-lib").requiredVersion)
2728
outputToConsole.set(true)
2829
enableExperimentalRules.set(true)
30+
filter {
31+
exclude("**/generated/**")
32+
exclude("**/build/**")
33+
}
2934
disabledRules.set(
3035
setOf(
3136
"max-line-length", // manually formatting still does this, and KTLint will still wrap long chains when possible
@@ -39,18 +44,21 @@ extensions.configure(KtlintExtension::class.java) {
3944
"experimental:function-signature"
4045
)
4146
)
42-
require(libsCatalog.version("ktlint-lib").requiredVersion < "0.46.0") {
43-
"""
44-
when updating to 0.46.0:
45-
- Re-enable `experimental:type-parameter-list-spacing`
46-
- remove 'experimental' from 'argument-list-wrapping'
47-
- remove 'experimental' from 'no-empty-first-line-in-method-block'
48-
""".trimIndent()
49-
}
50-
}
5147

52-
dependencies {
53-
"ktlintRuleset"(project(path = ":ktlint-rules"))
48+
extensions.configure(KtlintExtension::class.java) {
49+
50+
require(libVersion < "0.46.0") {
51+
"""
52+
when updating to 0.46.0:
53+
- Re-enable `experimental:type-parameter-list-spacing`
54+
- remove 'experimental' from 'argument-list-wrapping'
55+
- remove 'experimental' from 'no-empty-first-line-in-method-block'
56+
""".trimIndent()
57+
}
58+
}
59+
dependencies {
60+
"ktlintRuleset"(project(path = ":ktlint-rules"))
61+
}
5462
}
5563

5664
tasks.withType<org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask> {

build-logic/mcbuild/src/main/kotlin/modulecheck/builds/KspListener.kt renamed to build-logic/mcbuild/src/main/kotlin/modulecheck/builds/ArtifactIdExtension.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515

1616
package modulecheck.builds
1717

18-
fun interface KspListener {
19-
fun onChanged(useKsp: Boolean)
18+
interface ArtifactIdExtension {
19+
val artifactId: String?
2020
}

build-logic/mcbuild/src/main/kotlin/modulecheck/builds/ArtifactIdListener.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

build-logic/mcbuild/src/main/kotlin/modulecheck/builds/DIListener.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

build-logic/mcbuild/src/main/kotlin/modulecheck/builds/ksp.kt renamed to build-logic/mcbuild/src/main/kotlin/modulecheck/builds/DiExtension.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@
1515

1616
package modulecheck.builds
1717

18-
import org.gradle.api.Project
19-
import org.gradle.kotlin.dsl.apply
18+
interface DiExtension {
19+
/**
20+
* Applies the Anvil plugin with `generateDaggerFactories` set to `true`. Do not use at the same
21+
* time as `dagger()`.
22+
*/
23+
fun anvil()
2024

21-
fun Project.applyKsp(useKsp: Boolean) {
22-
23-
if (!useKsp) return
24-
25-
apply(plugin = "com.google.devtools.ksp")
25+
/**
26+
* Applies kapt and the Anvil plugin with `generateDaggerFactories` set to `false`. Also adds the
27+
* Dagger compiler `kapt` dependency.
28+
*
29+
* Do not use at the same time as `anvil()`.
30+
*/
31+
fun dagger()
2632
}

0 commit comments

Comments
 (0)