-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
158 lines (138 loc) · 4.25 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
158 lines (138 loc) · 4.25 KB
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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.facebook.ktfmt.GenerateKtfmtFileTask
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation
plugins {
kotlin("jvm")
alias(libs.plugins.dokka)
alias(libs.plugins.dokka.javadoc)
alias(libs.plugins.shadowJar)
id("maven-publish")
id("signing")
id("ktfmt.ktfmt-file-generator")
id("ktfmt.native-image")
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
api(libs.googleJavaformat)
api(libs.guava)
api(libs.jna)
api(libs.kotlin.stdlib)
api(libs.kotlin.compilerEmbeddable)
implementation(libs.ec4j)
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
testRuntimeOnly(libs.junit.platform.launcher)
}
val generateSources by tasks.registering {
outputs.dir(layout.buildDirectory.dir("generated/main/java"))
dependsOn(tasks.withType<GenerateKtfmtFileTask>())
}
tasks {
// Run tests with UTF-16 encoding
test {
useJUnitPlatform()
jvmArgs("-Dfile.encoding=UTF-16")
}
// Handle multiple versions of Kotlin here
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
// Only get major and minor version, e.g. 1.8.0-beta1 -> 1.8
val kotlinVersion = rootProject.libs.versions.kotlin.get().substringBeforeLast(".")
exclude {
val path = it.path
"com/facebook/ktfmt/util/kotlin-" in path && "kotlin-$kotlinVersion" !in path
}
}
// Add main class to jar manifest
withType(Jar::class) { manifest { attributes["Main-Class"] = "com.facebook.ktfmt.cli.Main" } }
// Sources
register("sourcesJar", Jar::class) {
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
// Javadoc
register("javadocJar", Jar::class) {
val dokkaJavadocTask = named(
"dokkaGeneratePublicationJavadoc",
org.jetbrains.dokka.gradle.tasks.DokkaGeneratePublicationTask::class,
)
dependsOn(dokkaJavadocTask)
from(dokkaJavadocTask.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}
// Fat jar
shadowJar {
archiveClassifier = "with-dependencies"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
failOnDuplicateEntries = true
}
}
kotlin {
@OptIn(ExperimentalAbiValidation::class) abiValidation { enabled = true }
val javaVersion: String = rootProject.libs.versions.java.get()
jvmToolchain(javaVersion.toInt())
sourceSets {
main {
kotlin {
// Include generated code
srcDir(generateSources)
}
}
}
}
group = "com.facebook"
version = rootProject.version
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "com.facebook"
artifactId = "ktfmt"
version = rootProject.version.toString()
from(components["java"])
artifact(tasks.named("sourcesJar"))
artifact(tasks.named("javadocJar"))
pom {
name = "Ktfmt"
description =
"A program that reformats Kotlin source code to comply with the common community standard for Kotlin code conventions."
url = "https://github.com/facebook/ktfmt"
inceptionYear = "2019"
developers { developer { name = "Facebook" } }
licenses {
license {
name = "The Apache License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
scm {
connection = "scm:git:https://github.com/facebook/ktfmt.git"
developerConnection = "scm:git:git@github.com:facebook/ktfmt.git"
url = "https://github.com/facebook/ktfmt.git"
}
}
}
}
}
if (System.getenv("SIGN_BUILD") != null) {
signing {
useGpgCmd()
sign(publishing.publications["maven"])
}
}