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

Feature/ktlint detekt #2

Merged
merged 8 commits into from
Jul 9, 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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ updates:
- package-ecosystem: gradle
directory: "/"
schedule:
interval: weekly
interval: monthly
open-pull-requests-limit: 10
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
# Module Graph Assert
A Gradle plugin that helps keep your module graph healthy and lean.

---

## What is changed in this fork

> [!IMPORTANT]
> Added support for Mermaid output format supported by GitHut / GitLab markdown. So we can draw dependency chart into markdown file.

### Usage for GitHub / GitLab markdown
```kotlin
// app/build.gradle.kts
plugins {
id("com.jraska.module.graph.assertion") version "2.5.0"
}


moduleGraphAssert {
configurations = setOf("api", "implementation")
assertOnAnyBuild = true
outputFormat = OutputFormat.MERMAID
outputFilePath = "$rootDir/dependency-graph.md"
}
```

---

- [Medium Article](https://proandroiddev.com/module-rules-protect-your-build-time-and-architecture-d1194c7cc6bc) with complete context.
- [Talk about module graph and why it matters](https://www.droidcon.com/2022/11/15/modularization-flatten-your-graph-and-get-the-real-benefits/)
- [Changelog](https://github.com/jraska/modules-graph-assert/releases)
Expand Down
21 changes: 0 additions & 21 deletions build.gradle

This file was deleted.

86 changes: 86 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version libs.versions.kotlin.get()
alias(libs.plugins.detekt)
alias(libs.plugins.ktlint)
}

kotlin {
jvmToolchain(
libs.versions.java
.get()
.toInt(),
)
}

java {
sourceCompatibility = JavaVersion.toVersion(libs.versions.java.get())
targetCompatibility = JavaVersion.toVersion(libs.versions.java.get())

toolchain.languageVersion.set(
JavaLanguageVersion.of(
libs.versions.java
.get()
.toInt(),
),
)
}

tasks.withType<JavaCompile> {
options.compilerArgs.addAll(
listOf(
"-source",
libs.versions.java.get(),
"-target",
libs.versions.java.get(),
),
)
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = libs.versions.java.get()
}

subprojects {
apply(
plugin =
rootProject.libs.plugins.ktlint
.get()
.pluginId,
)
apply(
plugin =
rootProject.libs.plugins.detekt
.get()
.pluginId,
)

tasks.withType<JavaCompile> {
options.compilerArgs.addAll(
listOf(
"-source",
libs.versions.java.get(),
"-target",
libs.versions.java.get(),
),
)
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version.set(
rootProject.libs.versions.ktlint
.get(),
)
verbose.set(true)
filter {
exclude("**/generated/**", "**/build/**")
include("src/**/kotlin")
}
}

detekt {
buildUponDefaultConfig = true
parallel = true
}
}
3 changes: 3 additions & 0 deletions config/ktlint/baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<baseline version="1.0">
</baseline>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
org.gradle.jvmargs=-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true
VERSION_NAME=0.1.0

kotlin.code.style=official
22 changes: 22 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[versions]
detekt = "1.23.5"
java = "17"
junit = "4.13.2"
kotlin = "2.0.0"
ktlint = "1.3.1"
ktlintGradle = "12.1.1"
pluginPublish = "1.2.1"

[libraries]
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
junit = { module = "junit:junit", version.ref = "junit" }


[plugins]
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt"}
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"}
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintGradle"}
pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish"}


[bundles]
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
46 changes: 0 additions & 46 deletions plugin/build.gradle

This file was deleted.

31 changes: 31 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
alias(libs.plugins.pluginPublish)
`java-gradle-plugin`
}

apply(plugin = "kotlin")

dependencies {
implementation(gradleApi())
implementation(libs.kotlin.stdlib)

implementation(libs.junit)
}

group = "cz.mtrakal.module.graph.assertion"

gradlePlugin {
website = "https://github.com/mtrakal/modules-graph-assert"
vcsUrl = "https://github.com/mtrakal/modules-graph-assert"

plugins {
create("modulesGraphAssert") {
id = "cz.mtrakal.module.graph.assertion"
version = "3.0.0"
displayName = "Modules Graph Assert Mermaid"
description = "Gradle plugin to keep your modules graph healthy and lean with Mermaid output."
implementationClass = "com.jraska.module.graph.assertion.ModuleGraphAssertionsPlugin"
tags.addAll("graph", "assert", "build speed", "android", "java", "kotlin", "quality", "multiprojects", "module", "mermaid")
}
}
}
10 changes: 10 additions & 0 deletions plugin/config/ktlint/baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<baseline version="1.0">
<file name="src/main/kotlin/com/jraska/module/graph/assertion/ModuleTreeHeightAssert.kt">
<error line="27" column="141" source="standard:max-line-length" />
<error line="37" column="141" source="standard:max-line-length" />
</file>
<file name="src/test/kotlin/com/jraska/module/graph/assertion/OnAnyBuildAssertTest.kt">
<error line="128" column="141" source="standard:max-line-length" />
</file>
</baseline>
17 changes: 17 additions & 0 deletions plugin/detekt-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" ?>
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>LongMethod:DependencyGraphTest.kt$DependencyGraphTest$@Test fun countsStatisticsWell()</ID>
<ID>MaxLineLength:ModuleTreeHeightAssert.kt$ModuleTreeHeightAssert$"Module $moduleName is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}"</ID>
<ID>MaxLineLength:ModuleTreeHeightAssert.kt$ModuleTreeHeightAssert$"Module Graph is allowed to have maximum height of $maxHeight, but has $height, problematic dependencies: ${longestPath.pathString()}"</ID>
<ID>MaxLineLength:OnAnyBuildAssertTest.kt$OnAnyBuildAssertTest$"""["App"(':app') -&gt; "Implementation"(':core'), "App"(':app') -&gt; "Implementation"(':feature')] not allowed by any of ['Implementation -&gt; Api', 'App -&gt; Api']"""</ID>
<ID>MaxLineLength:OnAnyBuildAssertTest.kt$OnAnyBuildAssertTest$"Module :app is allowed to have maximum height of 1, but has 2, problematic dependencies: :app -&gt; :core -&gt; :core-api"</ID>
<ID>ReturnCount:GradleDependencyGraphFactory.kt$GradleDependencyGraphFactory$fun create( project: Project, configurationsToLook: Set&lt;String&gt;, ): DependencyGraph</ID>
<ID>SerialVersionUIDInSerializableClass:DependencyGraph.kt$DependencyGraph$SerializableGraph : Serializable</ID>
<ID>SerialVersionUIDInSerializableClass:ModuleTreeHeightAssert.kt$ModuleTreeHeightAssert : GraphAssertSerializable</ID>
<ID>SwallowedException:ModuleGraphAssertionsPlugin.kt$ModuleGraphAssertionsPlugin$checkNotFound: UnknownTaskException</ID>
<ID>TooManyFunctions:DependencyGraph.kt$DependencyGraph</ID>
<ID>TooManyFunctions:ModuleGraphAssertionsPlugin.kt$ModuleGraphAssertionsPlugin : Plugin</ID>
</CurrentIssues>
</SmellBaseline>
Loading
Loading