Skip to content

Commit

Permalink
Merge pull request #2 from AJIEKCX/v0.1.0/release
Browse files Browse the repository at this point in the history
Prepare MavenCentral publication
  • Loading branch information
AJIEKCX authored Feb 15, 2025
2 parents 577f4a3 + 9b8900b commit cfa682f
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 94 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/cleanup.yaml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish to MavenCentral

on:
push:
tags:
- '*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: '21'
distribution: 'temurin'
- name: Build and publish with Gradle
uses: gradle/gradle-build-action@3
with:
arguments: --no-daemon -i jreleaserConfig build test publish
env:
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.JRELEASER_MAVENCENTRAL_SONATYPE_USERNAME }}
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.JRELEASER_MAVENCENTRAL_SONATYPE_TOKEN }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}

- name: Release with gradle
uses: gradle/gradle-build-action@3
with:
arguments: --no-daemon -i jreleaserFullRelease
env:
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.JRELEASER_MAVENCENTRAL_SONATYPE_USERNAME }}
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.JRELEASER_MAVENCENTRAL_SONATYPE_TOKEN }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/.gradle
/build
/local.properties
.kotlin
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright [2025] [Alexey Panov and contributors]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
56 changes: 36 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
# detekt custom rule template
# Decompose Detekt Rules
[![Maven Central](https://img.shields.io/maven-central/v/io.github.ajiekcx.detekt/decompose-detekt-rules?label=Maven%20Central)](https://central.sonatype.com/namespace/io.github.ajiekcx.detekt)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)

This repository is a template. You can use it to generate your own repository to write and share your custom rules.
[Decompose](https://github.com/arkivanov/Decompose) is a Kotlin Multiplatform library for breaking down your code into tree-structured lifecycle-aware business logic components (aka BLoC), with routing functionality and pluggable UI.
The Decompose Detekt Rules are a set of custom detekt rules that help you avoid critical mistakes when working with Decompose.

## How to use it
## Quick start

1. Create a new repository using this one as a template. [Click here][create_template]
2. Edit MyRule to fit your use case
3. Share your rule! You can upload your rule to [Maven Central][maven_central] if you want. If you don't want to do all
the steps that Maven Central requires you can just share your rule using [jitpack][jitpack].
4. Extra: you can remove all this README and explain what your rule does and how to configure it.
Specify the dependency on this set of rules using `detektPlugins`:

## Documentation
```kotlin
detektPlugins("io.github.ajiekcx.detekt:decompose-detekt-rules:0.1.0")
```

You can find the documentation about how to write [custom rules here][custom_rule_documentation].
## Rules

## Note
### DecomposeComponentContextRule

- Remember that, by default, all rules are disabled. To configure your rules edit the file in
`src/main/resources/config/config.yml`.
- Once you have your rules ready you can publish them on the [detekt's marketplace][detekt_marketplace] to improve the discoverability. To do so create a PR editing [this file][detekt_marketplace_edit].
A common mistake is to create a Decompose `ComponentContext` inside a Composable function scope. For example:
```kotlin
class MainActivity: ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

[create_template]: https://github.com/detekt/detekt-custom-rule-template/generate
setContent {
// DON'T DO THIS
val context = defaultComponentContext()
}
}
}
```

[maven_central]: https://search.maven.org/
If recomposition occurs without Activity recreation, you will get the following exception:
```
java.lang.IllegalArgumentException: SavedStateProvider with the given key is already registered
```

[custom_rule_documentation]: https://detekt.github.io/detekt/extensions.html
Avoid using the `defaultComponentContext` function inside Composable functions.

[jitpack]: https://jitpack.io/
## Enabling rules

[detekt_marketplace]: https://detekt.dev/marketplace
[detekt_marketplace_edit]: https://github.com/detekt/detekt/blob/main/website/src/data/marketplace.js
By default, all rules are enabled, but you can configure them in your `detekt.yml` configuration file:
```yaml
DecomposeRuleSet:
DecomposeComponentContextRule:
active: true
```
97 changes: 89 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import org.jreleaser.model.Active

plugins {
kotlin("jvm") version "2.1.10"
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.jreleaser)
`maven-publish`
}

group = "org.example.detekt"
version = "1.0-SNAPSHOT"
group = properties["GROUP"].toString()
version = properties["VERSION_NAME"].toString()
description = "Detekt ruleset for Decompose project"

dependencies {
compileOnly("io.gitlab.arturbosch.detekt:detekt-api:1.23.7")
compileOnly(libs.detekt.api)

testImplementation(libs.detekt.test)
testImplementation(libs.kotest)
testImplementation(libs.jupiter)
}

testImplementation("io.gitlab.arturbosch.detekt:detekt-test:1.23.7")
testImplementation("io.kotest:kotest-assertions-core:5.9.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
java {
withJavadocJar()
withSourcesJar()
}

kotlin {
Expand All @@ -26,8 +35,80 @@ tasks.withType<Test>().configureEach {

publishing {
publications {
create<MavenPublication>("mavenJava") {
create<MavenPublication>("release") {
from(components["java"])

groupId = properties["GROUP"].toString()
artifactId = "decompose-detekt-rules"

pom {
name.set(project.properties["POM_NAME"].toString())
description.set(project.description)
url.set("https://github.com/AJIEKCX/decompose-detekt-rules")
issueManagement {
url.set("https://github.com/AJIEKCX/decompose-detekt-rules/issues")
}

scm {
url.set("https://github.com/AJIEKCX/decompose-detekt-rules")
connection.set("scm:git://github.com/AJIEKCX/decompose-detekt-rules.git")
developerConnection.set("scm:git://github.com/AJIEKCX/decompose-detekt-rules.git")
}

licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}

developers {
developer {
id.set("AJIEKCX")
name.set("Alexey Panov")
email.set("panovalexsey@gmail.com")
}
}
}
}
}
repositories {
maven {
setUrl(layout.buildDirectory.dir("staging-deploy"))
}
}
}

jreleaser {
project {
inceptionYear = "2025"
author("@AJIEKCX")
}
release {
github {
skipRelease = true
skipTag = true
sign = true
branch = "main"
branchPush = "main"
overwrite = true
}
}
signing {
active = Active.ALWAYS
armored = true
verify = true
}
deploy {
maven {
mavenCentral.create("sonatype") {
active = Active.ALWAYS
url = "https://central.sonatype.com/api/v1/publisher"
stagingRepository(layout.buildDirectory.dir("staging-deploy").get().toString())
setAuthorization("Basic")
retryDelay = 60
}
}
}
}
22 changes: 0 additions & 22 deletions change_package_name.sh

This file was deleted.

3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
kotlin.code.style=official

GROUP=io.github.ajiekcx.detekt
VERSION_NAME=0.1.0
16 changes: 16 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[versions]
kotlin = "2.0.21"
detekt = "1.23.7"
kotest = "5.9.1"
jupiter = "5.11.4"
jreleaser = "1.16.0"

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
jreleaser = { id = "org.jreleaser", version.ref = "jreleaser" }

[libraries]
detekt-api = { module = "io.gitlab.arturbosch.detekt:detekt-api", version.ref = "detekt" }
detekt-test = { module = "io.gitlab.arturbosch.detekt:detekt-test", version.ref = "detekt" }
kotest = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "jupiter" }
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = "detekt-custom-rule"
rootProject.name = "decompose-detekt-rules"

dependencyResolutionManagement {
repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example.detekt
package io.github.ajiekcx.detekt

import io.gitlab.arturbosch.detekt.api.CodeSmell
import io.gitlab.arturbosch.detekt.api.Config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example.detekt
package io.github.ajiekcx.detekt

import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.RuleSet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example.detekt
package io.github.ajiekcx.detekt

import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtClass
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.example.detekt.DecomposeRuleSetProvider
io.github.ajiekcx.detekt.DecomposeRuleSetProvider
2 changes: 1 addition & 1 deletion src/main/resources/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DecomposeRuleSetProvider:
DecomposeRuleSet:
DecomposeComponentContextRule:
active: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example.detekt
package io.github.ajiekcx.detekt

import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.rules.KotlinCoreEnvironmentTest
Expand Down

0 comments on commit cfa682f

Please sign in to comment.