Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Split compiler plugin and its Gradle plugin into separate modules (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
3flex authored Oct 15, 2022
1 parent a4e5ba5 commit 7f3594d
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pre-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
- name: Build detekt-compiler-plugin
run: ./gradlew -p plugin-build build --stacktrace

- name: Build detekt-compiler-plugin-gradle-plugin
run: ./gradlew -p detekt-compiler-plugin-gradle-plugin build --stacktrace

- name: Run smoke test
run: ./gradlew -p plugin-build testPluginKotlinc

Expand Down
115 changes: 115 additions & 0 deletions detekt-compiler-plugin-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val kotlinVersion: String = libs.versions.kotlin.get()

val detektPluginVersion: String by project

group = "io.github.detekt"
version = detektPluginVersion

val detektPublication = "DetektPublication"

plugins {
alias(libs.plugins.kotlin)
id("maven-publish")
id("java-gradle-plugin")
`jvm-test-suite`
alias(libs.plugins.pluginPublishing)
alias(libs.plugins.gradleVersionz)
}

repositories {
mavenCentral()
mavenLocal()
}

dependencies {
compileOnly(gradleApi())
compileOnly(kotlin("gradle-plugin"))
compileOnly(kotlin("gradle-plugin-api"))

testImplementation(libs.assertj.core)
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs = listOf(
"-opt-in=kotlin.RequiresOptIn"
)
}

tasks.withType<Test>().configureEach {
testLogging {
// set options for log level LIFECYCLE
events = setOf(
org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED,
org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR,
org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT,
org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
)
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
}
}

testing {
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter(libs.versions.junit.get())
}
}
}

tasks {
val writeDetektVersionProperties by registering(WriteProperties::class) {
description = "Write the properties file with the Detekt version to be used by the plugin"
encoding = "UTF-8"
outputFile = file("$buildDir/versions.properties")
property("detektCompilerPluginVersion", project.version)
}

processResources {
from(writeDetektVersionProperties)
}
}

val sourcesJar by tasks.registering(Jar::class) {
dependsOn(tasks.classes)
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}

val javadocJar by tasks.registering(Jar::class) {
from(tasks.javadoc)
archiveClassifier.set("javadoc")
}

artifacts {
archives(sourcesJar)
archives(javadocJar)
}

gradlePlugin {
plugins {
register("detektCompilerPlugin") {
id = "io.github.detekt.gradle.compiler-plugin"
implementationClass = "io.github.detekt.gradle.DetektKotlinCompilerPlugin"
}
}
}

pluginBundle {
website = "https://detekt.github.io/detekt"
vcsUrl = "https://github.com/detekt/detekt-compiler-plugin"
description = "Static code analysis for Kotlin as a compiler plugin."
tags = listOf("kotlin", "detekt", "code-analysis")

(plugins) {
"detektCompilerPlugin" {
id = "io.github.detekt.gradle.compiler-plugin"
displayName = "Static code analysis for Kotlin"
}
}
}
8 changes: 8 additions & 0 deletions detekt-compiler-plugin-gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
detektPluginVersion=0.4.0

kotlinCompilerChecksum=f5216644ad81571e5db62ec2322fe07468927bda40f51147ed626a2884b55f9a

kotlin.code.style=official
systemProp.sonar.host.url=http://localhost:9000
systemProp.detektVersion=detektVersion
systemProp.file.encoding=UTF-8
15 changes: 15 additions & 0 deletions detekt-compiler-plugin-gradle-plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
rootProject.name = "detekt-compiler-plugin-gradle-plugin"

pluginManagement {
repositories {
gradlePluginPortal()
}
}

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.detekt.gradle

import io.github.detekt.compiler.plugin.Options
import io.github.detekt.gradle.extensions.KotlinCompileTaskDetektExtension
import io.github.detekt.gradle.extensions.ProjectDetektExtension
import org.gradle.api.Project
Expand Down Expand Up @@ -74,15 +73,15 @@ class DetektKotlinCompilerPlugin : KotlinCompilerPluginSupportPlugin {
}

val options = project.objects.listProperty(SubpluginOption::class.java).apply {
add(SubpluginOption(Options.debug, taskExtension.debug.get().toString()))
add(SubpluginOption(Options.configDigest, taskExtension.config.toDigest()))
add(SubpluginOption(Options.isEnabled, taskExtension.isEnabled.get().toString()))
add(SubpluginOption(Options.useDefaultConfig, taskExtension.buildUponDefaultConfig.get().toString()))
add(SubpluginOption(Options.allRules, taskExtension.allRules.get().toString()))
add(SubpluginOption(Options.disableDefaultRuleSets, taskExtension.disableDefaultRuleSets.get().toString()))
add(SubpluginOption(Options.parallel, taskExtension.parallel.get().toString()))
add(SubpluginOption(Options.rootPath, project.rootDir.toString()))
add(SubpluginOption(Options.excludes, taskExtension.excludes.get().encodeToBase64()))
add(SubpluginOption("debug", taskExtension.debug.get().toString()))
add(SubpluginOption("configDigest", taskExtension.config.toDigest()))
add(SubpluginOption("isEnabled", taskExtension.isEnabled.get().toString()))
add(SubpluginOption("useDefaultConfig", taskExtension.buildUponDefaultConfig.get().toString()))
add(SubpluginOption("allRules", taskExtension.allRules.get().toString()))
add(SubpluginOption("disableDefaultRuleSets", taskExtension.disableDefaultRuleSets.get().toString()))
add(SubpluginOption("parallel", taskExtension.parallel.get().toString()))
add(SubpluginOption("rootDir", project.rootDir.toString()))
add(SubpluginOption("excludes", taskExtension.excludes.get().encodeToBase64()))

taskExtension.reports.all { report ->
report.enabled.convention(true)
Expand All @@ -93,17 +92,17 @@ class DetektKotlinCompilerPlugin : KotlinCompilerPluginSupportPlugin {
if (report.enabled.get()) {
add(
SubpluginOption(
Options.report,
"report",
"${report.name}:${report.destination.asFile.get().absolutePath}"
)
)
}
}
}

taskExtension.baseline.getOrNull()?.let { options.add(SubpluginOption(Options.baseline, it.toString())) }
taskExtension.baseline.getOrNull()?.let { options.add(SubpluginOption("baseline", it.toString())) }
if (taskExtension.config.any()) {
options.add(SubpluginOption(Options.config, taskExtension.config.joinToString(",")))
options.add(SubpluginOption("config", taskExtension.config.joinToString(",")))
}

return options
Expand Down
28 changes: 0 additions & 28 deletions plugin-build/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ val detektPublication = "DetektPublication"
plugins {
alias(libs.plugins.kotlin)
id("maven-publish")
id("java-gradle-plugin")
`jvm-test-suite`
alias(libs.plugins.pluginPublishing)
alias(libs.plugins.gradleVersionz)
alias(libs.plugins.shadow)
alias(libs.plugins.download)
Expand All @@ -30,9 +28,6 @@ repositories {
}

dependencies {
compileOnly(gradleApi())
compileOnly(kotlin("gradle-plugin"))
compileOnly(kotlin("gradle-plugin-api"))
compileOnly(kotlin("stdlib"))
compileOnly(kotlin("compiler-embeddable"))

Expand Down Expand Up @@ -176,26 +171,3 @@ artifacts {
archives(sourcesJar)
archives(javadocJar)
}

gradlePlugin {
plugins {
register("detektCompilerPlugin") {
id = "io.github.detekt.gradle.compiler-plugin"
implementationClass = "io.github.detekt.gradle.DetektKotlinCompilerPlugin"
}
}
}

pluginBundle {
website = "https://detekt.github.io/detekt"
vcsUrl = "https://github.com/detekt/detekt-compiler-plugin"
description = "Static code analysis for Kotlin as a compiler plugin."
tags = listOf("kotlin", "detekt", "code-analysis")

(plugins) {
"detektCompilerPlugin" {
id = "io.github.detekt.gradle.compiler-plugin"
displayName = "Static code analysis for Kotlin"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.detekt.compiler.plugin

import io.github.detekt.gradle.DETEKT_COMPILER_PLUGIN
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CliOptionProcessingException
Expand All @@ -13,7 +12,7 @@ import java.util.Base64

class DetektCommandLineProcessor : CommandLineProcessor {

override val pluginId: String = DETEKT_COMPILER_PLUGIN
override val pluginId: String = "detekt-compiler-plugin"

override val pluginOptions: Collection<AbstractCliOption> = listOf(
CliOption(
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionW
rootProject.name = "detekt-compiler-plugin-composite-build"

includeBuild("plugin-build")
includeBuild("detekt-compiler-plugin-gradle-plugin")

plugins {
id("com.gradle.enterprise") version "3.11.1"
Expand Down

0 comments on commit 7f3594d

Please sign in to comment.