Skip to content

Commit

Permalink
Update config
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yevsyukov committed Nov 1, 2022
1 parent 7f703b4 commit b8fe735
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 26 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/detekt-code-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run Detekt code analysis

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: 'true'

- uses: actions/setup-java@v3
with:
java-version: 11
distribution: zulu
cache: gradle

- name: Run analysis
shell: bash
run: ./gradlew detekt --stacktrace
32 changes: 23 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,52 @@ import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
apply(from = "$rootDir/version.gradle.kts")

io.spine.internal.gradle.doApplyStandard(repositories)
io.spine.internal.gradle.doApplyGitHubPackages(repositories, "base", rootProject)
/**
* Applies repositories putting those at GitHub first for faster CI builds.
*/
fun ScriptHandlerScope.applyRepositories() {
val gitHub: (String) -> Unit = { repo ->
io.spine.internal.gradle.doApplyGitHubPackages(repositories, repo, rootProject)
}
gitHub("base")
gitHub("time")
gitHub("tool-base")
io.spine.internal.gradle.doApplyStandard(repositories)
}

val spine = io.spine.internal.dependency.Spine(project)
applyRepositories()

dependencies {
classpath(spine.mcJavaPlugin)
classpath(io.spine.internal.dependency.Spine.McJava.pluginLib)
}

io.spine.internal.gradle.doForceVersions(configurations)
configurations.all {
resolutionStrategy {
val spine = io.spine.internal.dependency.Spine(project)
val kotlin = io.spine.internal.dependency.Kotlin
force(
io.spine.internal.dependency.Kotlin.stdLib,
io.spine.internal.dependency.Kotlin.stdLibCommon,
kotlin.stdLib,
kotlin.stdLibCommon,
spine.base,
spine.time,
spine.toolBase,
)
}
}

}

@Suppress("RemoveRedundantQualifierName") // Cannot use imports here.
plugins {
`java-library`
kotlin("jvm")
idea
id(io.spine.internal.dependency.Protobuf.GradlePlugin.id)
id(io.spine.internal.dependency.ErrorProne.GradlePlugin.id)
id(protobufPlugin)
id(errorPronePlugin)
id(gradleDoctor.pluginId) version gradleDoctor.version
`detekt-code-analysis`
}

object BuildSettings {
Expand Down
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ val protobufPluginVersion = "0.8.19"
*/
val dokkaVersion = "1.7.20"

/**
* The version of Detekt Gradle Plugin.
*
* @see <a href="https://github.com/detekt/detekt/releases">Detekt Releases</a>
*/
val detektVersion = "1.21.0"

configurations.all {
resolutionStrategy {
force(
Expand Down Expand Up @@ -142,6 +149,7 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")

implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detektVersion")
implementation("com.google.protobuf:protobuf-gradle-plugin:$protobufPluginVersion")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:${dokkaVersion}")
implementation("org.jetbrains.dokka:dokka-base:${dokkaVersion}")
Expand Down
60 changes: 60 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

@file:Suppress("unused", "UnusedReceiverParameter")

import io.spine.internal.dependency.ErrorProne
import io.spine.internal.dependency.GradleDoctor
import io.spine.internal.dependency.Protobuf
import io.spine.internal.dependency.Spine
import io.spine.internal.dependency.Spine.ProtoData
import org.gradle.plugin.use.PluginDependenciesSpec

/**
* Allows to escape a fully qualified names for dependencies which cannot be used
* under `plugins` section because `io` is a value declared in
* `org.gradle.kotlin.dsl.PluginAccessors.kt`.
*
* We still want to keep versions numbers in [io.spine.internal.dependency.Spine]
* for the time being. So this file allows to reference those without resorting
* to using strings again.
*/
private const val ABOUT = ""

val PluginDependenciesSpec.protoData: ProtoData
get() = ProtoData

val PluginDependenciesSpec.errorPronePlugin: String
get() = ErrorProne.GradlePlugin.id

val PluginDependenciesSpec.protobufPlugin: String
get() = Protobuf.GradlePlugin.id

val PluginDependenciesSpec.gradleDoctor: GradleDoctor
get() = GradleDoctor

val PluginDependenciesSpec.mcJava: Spine.McJava
get() = Spine.McJava
57 changes: 57 additions & 0 deletions buildSrc/src/main/kotlin/config-tester.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import io.spine.internal.gradle.ConfigTester
import io.spine.internal.gradle.SpineRepos
import io.spine.internal.gradle.cleanFolder
import java.nio.file.Path
import java.nio.file.Paths

// A reference to `config` to use along with the `ConfigTester`.
val config: Path = Paths.get("./")

// A temp folder to use to check out the sources of other repositories with the `ConfigTester`.
val tempFolder = File("./tmp")

// Creates a Gradle task which checks out and builds the selected Spine repositories
// with the local version of `config` and `config/buildSrc`.
ConfigTester(config, tasks, tempFolder)
.addRepo(SpineRepos.baseTypes) // Builds `base-types` at `master`.
.addRepo(SpineRepos.base) // Builds `base` at `master`.
.addRepo(SpineRepos.coreJava) // Builds `core-java` at `master`.

// This is how one builds a specific branch of some repository:
// .addRepo(SpineRepos.coreJava, Branch("grpc-concurrency-fixes"))

// Register the produced task under the selected name to invoke manually upon need.
.registerUnder("buildDependants")

// Cleans the temp folder used to check out the sources from Git.
tasks.register("clean") {
doLast {
cleanFolder(tempFolder)
}
}
84 changes: 84 additions & 0 deletions buildSrc/src/main/kotlin/detekt-code-analysis.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import io.gitlab.arturbosch.detekt.Detekt

/**
* This script-plugin sets up Kotlin code analyzing with Detekt.
*
* After applying, Detekt is configured to use `${rootDir}/config/quality/detekt-config.yml` file.
* Projects can append their own config files to override some parts of the default one or drop
* it at all in a favor of their own one.
*
* An example of appending a custom config file to the default one:
*
* ```
* detekt {
* config.from("config/detekt-custom-config.yml")
* }
* ```
*
* To totally substitute it, just overwrite the corresponding property:
*
* ```
* detekt {
* config = files("config/detekt-custom-config.yml")
* }
* ```
*
* Also, it's possible to suppress Detekt findings using [baseline](https://detekt.dev/docs/introduction/baseline/)
* file instead of suppressions in source code.
*
* An example of passing a baseline file:
*
* ```
* detekt {
* baseline = file("config/detekt-baseline.yml")
* }
* ```
*/
private val about = ""

plugins {
id("io.gitlab.arturbosch.detekt")
}

detekt {
buildUponDefaultConfig = true
config = files("${rootDir}/config/quality/detekt-config.yml")
}

tasks {
withType<Detekt>().configureEach {
reports {
html.required.set(true) // Only HTML report is generated.
xml.required.set(false)
txt.required.set(false)
sarif.required.set(false)
md.required.set(false)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.internal.dependency

/**
* Helps optimize Gradle Builds by ensuring recommendations at build time.
*
* See [plugin site](https://runningcode.github.io/gradle-doctor) for features and usage.
*/
object GradleDoctor {
const val version = "0.8.1"
const val pluginId = "com.osacky.doctor"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

package io.spine.internal.dependency


@Suppress("unused")
object Jackson {
const val version = "2.13.4"
Expand Down
Loading

0 comments on commit b8fe735

Please sign in to comment.