forked from jeremymailen/kotlinter-gradle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
163 lines (141 loc) · 4.75 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
plugins {
`java-gradle-plugin`
`maven-publish`
idea
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.gradle.publish)
// Remove temporarily until 2.1.0 compatibility is released
// alias(libs.plugins.kotlinter)
}
repositories {
mavenCentral()
google()
}
val pluginId = "org.jmailen.kotlinter"
val githubUrl = "https://github.com/jeremymailen/kotlinter-gradle"
val webUrl = "https://github.com/jeremymailen/kotlinter-gradle"
val projectDescription = "Lint and formatting for Kotlin using ktlint with configuration-free setup on JVM and Android projects"
version = "5.0.1"
group = "org.jmailen.gradle"
description = projectDescription
configurations {
register("testRuntimeDependencies") {
extendsFrom(compileOnly.get())
attributes {
// KGP publishes multiple variants https://kotlinlang.org/docs/whatsnew17.html#support-for-gradle-plugin-variants
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY))
}
}
configureEach {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.kotlin" && requested.name.startsWith("kotlin")) {
useVersion(getKotlinPluginVersion())
}
}
}
}
dependencies {
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin")
compileOnly(libs.android.tools.gradle)
compileOnly(libs.bundles.ktlint.engine)
compileOnly(libs.bundles.ktlint.reporters)
compileOnly(libs.bundles.ktlint.rulesets)
testImplementation(libs.bundles.ktlint.engine)
testImplementation(libs.bundles.ktlint.reporters)
testImplementation(libs.bundles.ktlint.rulesets)
testImplementation(libs.bundles.junit.jupiter)
testImplementation(libs.commons.io)
testImplementation(libs.mockito.kotlin)
}
kotlin {
jvmToolchain(21)
}
tasks {
val generateVersionProperties = register("generateVersionProperties") {
val projectVersion = version
val propertiesFile = File(sourceSets.main.get().output.resourcesDir, "version.properties")
inputs.property("projectVersion", projectVersion)
outputs.file(propertiesFile)
doLast {
propertiesFile.writeText(
"""
version = $projectVersion
ktlintVersion = ${libs.versions.ktlint.get()}
""".trimIndent()
)
}
}
processResources {
dependsOn(generateVersionProperties)
}
withType<JavaCompile>().configureEach {
options.release.set(JavaVersion.VERSION_1_8.majorVersion.toInt())
}
withType<KotlinJvmCompile>().configureEach {
compilerOptions {
apiVersion.set(KotlinVersion.KOTLIN_1_8)
languageVersion.set(KotlinVersion.KOTLIN_1_8)
jvmTarget.set(JvmTarget.JVM_1_8)
}
}
withType<Test>().configureEach {
useJUnitPlatform()
}
// Required to put the Kotlin plugin on the classpath for the functional test suite
withType<PluginUnderTestMetadata>().configureEach {
pluginClasspath.from(configurations.getByName("testRuntimeDependencies"))
}
wrapper {
gradleVersion = "8.11.1"
}
}
gradlePlugin {
website.set(webUrl)
vcsUrl.set(githubUrl)
plugins {
create("kotlinterPlugin") {
id = pluginId
displayName = "Kotlin Lint plugin"
description = project.description
tags.addAll(listOf("kotlin", "ktlint", "lint", "format", "style", "android"))
implementationClass = "org.jmailen.gradle.kotlinter.KotlinterPlugin"
}
}
}
java {
withSourcesJar()
}
publishing {
publications.withType<MavenPublication> {
pom {
name.set(project.name)
description.set(project.description)
url.set(webUrl)
scm {
url.set(githubUrl)
}
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("jeremymailen")
name.set("Jeremy Mailen")
}
developer {
id.set("mateuszkwiecinski")
name.set("Mateusz Kwieciński")
}
}
}
}
}