Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2: Detekt configuration clean up #148

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions android/build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ gradlePlugin {
implementationClass = "com.theguardian.convention.ComposeApplicationConventionPlugin"
version = "1"
}
register("guardianDetektPlugin") {
id = "com.theguardian.detekt"
implementationClass = "com.theguardian.convention.DetektPlugin"
version = "1"
}
register("androidTestPlugin") {
id = "com.theguardian.test.android"
implementationClass = "com.theguardian.convention.AndroidTestConventionPlugin"
Expand Down
23 changes: 17 additions & 6 deletions android/build-logic/convention/gradle-lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.7.2" type="baseline" client="gradle" dependencies="false" name="AGP (8.7.2)" variant="all" version="8.7.2">
<issues format="6" by="lint 8.7.3" type="baseline" client="gradle" dependencies="false" name="AGP (8.7.3)" variant="all" version="8.7.3">

<issue
id="GradleProjectIsolation"
message="Avoid using method getRootProject"
errorLine1=" val rootProject = target.rootProject"
errorLine2=" ~~~~~~~~~~~">
errorLine1=" rootProject.layout.buildDirectory.file(&quot;reports/detekt/merge.sarif&quot;),"
errorLine2=" ~~~~~~~~~~~">
<location
file="src/main/kotlin/com/theguardian/convention/DetektPlugin.kt"
line="23"
column="38"/>
file="src/main/kotlin/com/theguardian/convention/shared/SetupDetekt.kt"
line="20"
column="17"/>
</issue>

<issue
id="GradleProjectIsolation"
message="Avoid using method getRootProject"
errorLine1=" basePath = rootProject.projectDir.absolutePath"
errorLine2=" ~~~~~~~~~~~">
<location
file="src/main/kotlin/com/theguardian/convention/shared/SetupDetekt.kt"
line="57"
column="24"/>
</issue>

</issues>
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.theguardian.convention

import com.android.build.api.dsl.ApplicationExtension
import com.theguardian.convention.shared.configureAndroidModule
import com.theguardian.convention.shared.configureAndroidTests
import com.theguardian.convention.shared.libs
import com.theguardian.convention.shared.plugin
import com.theguardian.convention.shared.*
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
Expand All @@ -29,6 +26,8 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
apply(libs.plugin("kotlinter").pluginId)
}

setupDetekt()

extensions.configure<ApplicationExtension> {
defaultConfig {
targetSdk = libs.findVersion("targetsdk").get().toString().toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
apply(libs.plugin("kotlinter").pluginId)
}

setupDetekt()

extensions.configure<LibraryExtension> {
configureAndroidModule<KotlinAndroidProjectExtension>(this)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.theguardian.convention

import com.android.build.gradle.TestExtension
import com.theguardian.convention.shared.configureAndroidModule
import com.theguardian.convention.shared.configureAndroidTests
import com.theguardian.convention.shared.libs
import com.theguardian.convention.shared.plugin
import com.theguardian.convention.shared.*
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
Expand All @@ -29,6 +26,8 @@ class AndroidTestConventionPlugin : Plugin<Project> {
apply(libs.plugin("kotlinter").pluginId)
}

setupDetekt()

extensions.configure<TestExtension> {
configureAndroidModule<KotlinAndroidProjectExtension>(this)

Expand Down
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to SetupDetekt.kt below.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.theguardian.convention
import com.theguardian.convention.shared.addBaseDependencies
import com.theguardian.convention.shared.libs
import com.theguardian.convention.shared.plugin
import com.theguardian.convention.shared.setupDetekt
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
Expand All @@ -24,6 +25,8 @@ class KotlinLibraryConventionPlugin : Plugin<Project> {
apply(libs.plugin("kotlinter").pluginId)
}

setupDetekt()

addBaseDependencies<KotlinJvmProjectExtension>()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.theguardian.convention.shared

import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import io.gitlab.arturbosch.detekt.report.ReportMergeTask
import org.gradle.api.JavaVersion
import org.gradle.api.Project

/**
* The Detekt convention plugin applies detekt plugins, and sets up configuration based on settings.
*/
fun Project.setupDetekt() {
with(this) {
with(pluginManager) {
this.apply(libs.plugin("detekt").pluginId)
}

tasks.register("reportMerge", ReportMergeTask::class.java) {
output.set(
rootProject.layout.buildDirectory.file("reports/detekt/merge.sarif"),
)
}

val reportMerge = tasks.named("reportMerge", ReportMergeTask::class.java)

reportMerge.configure {
input.from(tasks.withType(Detekt::class.java).map { it.sarifReportFile })
}

// enable reports
tasks.withType(Detekt::class.java).configureEach {
jvmTarget = JavaVersion.VERSION_17.toString()
reports {
xml.required.set(false)
html.required.set(true)
txt.required.set(true)
md.required.set(false)

sarif.required.set(true)
}

exclude(
"**/build/*",
"**/generated/*",
"**/build.gradle.kts",
"**/settings.gradle.kts",
)

finalizedBy(reportMerge)
}

extensions.configure(DetektExtension::class.java) {
toolVersion = libs.findVersion("detekt").get().requiredVersion
config.setFrom(file("${rootDir}/config/detekt.yml"))
parallel = true

basePath = rootProject.projectDir.absolutePath
ignoredBuildTypes = listOf("release")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the additional change here - ignoring release builds.


if (!isJvmModule()) {
// By default only main and test sources are included. I've added androidTest too
source.from("src/androidTest/java", "src/androidTest/kotlin")
}
}
}
}
3 changes: 1 addition & 2 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,4 @@ guardian-library-android = { id = "com.theguardian.library.android", version.ref
guardian-test-android = { id = "com.theguardian.test.android", version.ref = "guardian-convention-plugins" }
guardian-library-kotlin = { id = "com.theguardian.library.kotlin", version.ref = "guardian-convention-plugins" }
guardian-compose-library = { id = "com.theguardian.compose.library", version.ref = "guardian-convention-plugins" }
guardian-compose-application = { id = "com.theguardian.compose.application", version.ref = "guardian-convention-plugins" }
guardian-detekt = { id = "com.theguardian.detekt", version.ref = "guardian-convention-plugins" }
guardian-compose-application = { id = "com.theguardian.compose.application", version.ref = "guardian-convention-plugins" }
1 change: 0 additions & 1 deletion android/sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
alias(libs.plugins.guardian.application)
alias(libs.plugins.guardian.compose.application)
alias(libs.plugins.guardian.detekt)
}

android {
Expand Down
1 change: 0 additions & 1 deletion android/source/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
signing
alias(libs.plugins.guardian.library.android)
alias(libs.plugins.guardian.compose.library)
alias(libs.plugins.guardian.detekt)
}

android {
Expand Down
Loading