Skip to content

Commit 835c281

Browse files
committed
chore: refactor build script to convention plugins
1 parent d7448da commit 835c281

24 files changed

+588
-293
lines changed

build.gradle.kts

Lines changed: 7 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -17,119 +17,29 @@
1717
import org.gradle.plugins.ide.idea.model.IdeaProject
1818
import org.jetbrains.gradle.ext.CopyrightConfiguration
1919
import org.jetbrains.gradle.ext.ProjectSettings
20-
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
21-
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
22-
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
2320

2421
plugins {
25-
id("com.gradle.plugin-publish") apply false
26-
id("com.github.autostyle")
2722
id("org.jetbrains.gradle.plugin.idea-ext")
28-
id("org.jetbrains.dokka")
29-
`embedded-kotlin`
3023
}
3124

3225
description = "A set of plugins to simplify Gradle release tasks"
33-
val repoUrl = "https://github.com/vlsi/vlsi-release-plugins"
26+
val repoUrl = property("repoUrl")
3427

3528
val publishToCentral = (findProperty("publishToCentral") as? String)
3629
?.ifBlank { "true" }?.toBoolean() ?: true
3730

38-
if (publishToCentral) {
39-
}
31+
val release = providers.gradleProperty("release").getOrElse("false").toBoolean()
32+
val buildVersion = providers.gradleProperty("project.version").get() + if (release) "" else "-SNAPSHOT"
33+
34+
println("Building $buildVersion")
35+
version = buildVersion
4036

4137
allprojects {
4238
group = "com.github.vlsi.gradle"
43-
version = project.findProperty("project.version") as? String ?: rootProject.version
44-
45-
tasks.withType<GenerateModuleMetadata> {
46-
enabled = false
47-
}
48-
49-
plugins.withId("java") {
50-
configure<JavaPluginExtension> {
51-
withSourcesJar()
52-
}
53-
tasks.withType<JavaCompile>().configureEach {
54-
options.release.set(8)
55-
}
56-
}
57-
tasks.withType<KotlinJvmCompile>().configureEach {
58-
compilerOptions {
59-
freeCompilerArgs.add("-Xjdk-release=8")
60-
@Suppress("DEPRECATION")
61-
apiVersion.set(KotlinVersion.KOTLIN_1_4)
62-
jvmTarget = JvmTarget.JVM_1_8
63-
}
64-
}
39+
version = buildVersion
6540
}
6641

6742
val licenseHeader = file("gradle/license-header.txt").readText()
68-
allprojects {
69-
if (project.path != ":plugins:license-gather-plugin") {
70-
apply(plugin = "com.github.autostyle")
71-
autostyle {
72-
kotlinGradle {
73-
ktlint {
74-
userData(mapOf("disabled_rules" to "no-wildcard-imports,import-ordering"))
75-
}
76-
trimTrailingWhitespace()
77-
endWithNewline()
78-
}
79-
}
80-
plugins.withId("org.jetbrains.kotlin.jvm") {
81-
autostyle {
82-
kotlin {
83-
licenseHeader(licenseHeader)
84-
trimTrailingWhitespace()
85-
// Generated build/generated-sources/licenses/com/github/vlsi/gradle/license/api/License.kt
86-
// has wrong indentation, and it is not clear how to exclude it
87-
ktlint {
88-
userData(mapOf("disabled_rules" to "no-wildcard-imports,import-ordering"))
89-
}
90-
// It prints errors regarding build/generated-sources/licenses/com/github/vlsi/gradle/license/api/License.kt
91-
// so comment it for now :(
92-
endWithNewline()
93-
}
94-
}
95-
}
96-
}
97-
98-
tasks.withType<AbstractArchiveTask>().configureEach {
99-
// Ensure builds are reproducible
100-
isPreserveFileTimestamps = false
101-
isReproducibleFileOrder = true
102-
dirPermissions {
103-
user {
104-
read = true
105-
write = true
106-
execute = true
107-
}
108-
group {
109-
read = true
110-
write = true
111-
execute = true
112-
}
113-
other {
114-
read = true
115-
execute = true
116-
}
117-
}
118-
filePermissions {
119-
user {
120-
read = true
121-
write = true
122-
}
123-
group {
124-
read = true
125-
write = true
126-
}
127-
other {
128-
read = true
129-
}
130-
}
131-
}
132-
}
13343

13444
fun IdeaProject.settings(configuration: ProjectSettings.() -> kotlin.Unit) =
13545
(this as ExtensionAware).configure(configuration)

buildSrc/build.gradle.kts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion
12
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
44

55
/*
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
2020
*/
2121

2222
plugins {
23-
`java`
24-
`kotlin-dsl` apply false
23+
id("java")
24+
`kotlin-dsl`
2525
id("com.github.autostyle")
2626
}
2727

@@ -55,17 +55,28 @@ fun Project.applyKotlinProjectConventions() {
5555
apply(plugin = "org.gradle.kotlin.kotlin-dsl")
5656

5757
java {
58-
sourceCompatibility = JavaVersion.VERSION_1_8
59-
targetCompatibility = JavaVersion.VERSION_1_8
58+
toolchain {
59+
languageVersion.set(JavaLanguageVersion.of(21))
60+
}
61+
}
62+
tasks.withType<JavaCompile>().configureEach {
63+
options.release.set(11)
6064
}
61-
tasks.withType<KotlinJvmCompile> {
65+
tasks.withType<KotlinJvmCompile>().configureEach {
6266
compilerOptions {
63-
jvmTarget = JvmTarget.JVM_1_8
67+
jvmTarget = JvmTarget.JVM_11
68+
freeCompilerArgs.add("-Xjdk-release=11")
6469
}
6570
}
6671
}
6772

6873
dependencies {
74+
api("com.github.autostyle:com.github.autostyle.gradle.plugin:4.0")
75+
api("com.gradle.plugin-publish:com.gradle.plugin-publish.gradle.plugin:1.3.1")
76+
api("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$expectedKotlinDslPluginsVersion")
77+
api("org.jetbrains.dokka-javadoc:org.jetbrains.dokka-javadoc.gradle.plugin:2.0.0")
78+
api("com.gradleup.nmcp:com.gradleup.nmcp.gradle.plugin:0.1.5")
79+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin")
6980
subprojects.forEach {
7081
runtimeOnly(project(it.path))
7182
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2019 Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
plugins {
19+
id("java-base")
20+
id("org.jetbrains.dokka-javadoc")
21+
}
22+
23+
java {
24+
// Workaround https://github.com/gradle/gradle/issues/21933, so it adds javadocElements configuration
25+
withJavadocJar()
26+
}
27+
28+
val dokkaJar by tasks.registering(Jar::class) {
29+
group = LifecycleBasePlugin.BUILD_GROUP
30+
description = "Assembles a jar archive containing javadoc"
31+
from(tasks.dokkaGeneratePublicationJavadoc)
32+
archiveClassifier.set("javadoc")
33+
}
34+
35+
configurations[JavaPlugin.JAVADOC_ELEMENTS_CONFIGURATION_NAME].outgoing.artifact(dokkaJar)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2019 Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
import com.github.vlsi.gradle.buildtools.filterEolSimple
19+
20+
plugins {
21+
id("java")
22+
id("build.reproducible-timestamps")
23+
}
24+
25+
java {
26+
toolchain {
27+
languageVersion.set(JavaLanguageVersion.of(21))
28+
}
29+
}
30+
31+
tasks.withType<JavaCompile>().configureEach {
32+
options.release.set(8)
33+
options.encoding = "UTF-8"
34+
}
35+
36+
tasks.withType<Jar>().configureEach {
37+
into("META-INF") {
38+
filterEolSimple("crlf")
39+
from("$rootDir/LICENSE")
40+
from("$rootDir/NOTICE")
41+
}
42+
manifest {
43+
attributes["Bundle-License"] = "Apache-2.0"
44+
attributes["Specification-Title"] = project.name + " " + project.description
45+
attributes["Specification-Vendor"] = "Vladimir Sitnikov"
46+
attributes["Implementation-Vendor"] = "Vladimir Sitnikov"
47+
attributes["Implementation-Vendor-Id"] = "com.github.vlsi"
48+
// Implementation-Version is not here to make jar reproducible across versions
49+
}
50+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2019 Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
19+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
20+
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
21+
22+
plugins {
23+
id("build.java-conventions")
24+
id("com.github.autostyle")
25+
kotlin("jvm")
26+
}
27+
28+
tasks.withType<KotlinJvmCompile>().configureEach {
29+
compilerOptions {
30+
freeCompilerArgs.add("-Xjdk-release=8")
31+
@Suppress("DEPRECATION")
32+
apiVersion.set(KotlinVersion.KOTLIN_1_4)
33+
jvmTarget = JvmTarget.JVM_1_8
34+
}
35+
}
36+
37+
val licenseHeader = file("gradle/license-header.txt").takeIf { it.exists() }?.readText()
38+
39+
if (licenseHeader != null) {
40+
autostyle {
41+
kotlinGradle {
42+
ktlint {
43+
userData(mapOf("disabled_rules" to "no-wildcard-imports,import-ordering"))
44+
}
45+
trimTrailingWhitespace()
46+
endWithNewline()
47+
}
48+
kotlin {
49+
licenseHeader(licenseHeader)
50+
trimTrailingWhitespace()
51+
// Generated build/generated-sources/licenses/com/github/vlsi/gradle/license/api/License.kt
52+
// has wrong indentation, and it is not clear how to exclude it
53+
ktlint {
54+
userData(mapOf("disabled_rules" to "no-wildcard-imports,import-ordering"))
55+
}
56+
// It prints errors regarding build/generated-sources/licenses/com/github/vlsi/gradle/license/api/License.kt
57+
// so comment it for now :(
58+
endWithNewline()
59+
}
60+
}
61+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2019 Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
plugins {
19+
id("org.gradle.kotlin.kotlin-dsl")
20+
id("build.kotlin-conventions")
21+
id("build.dokka-javadoc")
22+
id("build.publish-to-central")
23+
}
24+
25+
val pluginDisplayName = project.property("plugin.display.name") as String
26+
27+
val repoUrl = property("repoUrl") as String
28+
29+
gradlePlugin {
30+
description = project.description
31+
website = repoUrl
32+
vcsUrl = repoUrl
33+
34+
val pluginId = project.name.removeSuffix("-plugin")
35+
plugins {
36+
create(pluginId) {
37+
id = "com.github.vlsi.$pluginId"
38+
displayName = pluginDisplayName
39+
description = project.description
40+
tags = (property("plugin.tags") as String).split(Regex("\\s*,\\s*"))
41+
implementationClass = project.property("plugin.implementation.class") as String
42+
}
43+
}
44+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2019 Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
plugins {
19+
kotlin("jvm")
20+
id("build.kotlin-conventions")
21+
}

0 commit comments

Comments
 (0)