Skip to content

chore: refactor build script to convention plugins #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,25 @@ on:

jobs:
build:
strategy:
fail-fast: true
matrix:
java-version:
- 8
- 11
gradle-version: [wrapper]
name: 'Test, Java ${{ matrix.java-version }}'
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 50
submodules: true
- name: 'Set up JDK ${{ matrix.java-version }}'
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
java-version: |
8
21
distribution: 'zulu'
- name: 'Test'
- name: Test
uses: burrunan/gradle-cache-action@v3
with:
job-id: jdk${{ matrix.java-version }}
gradle-version: ${{ matrix.gradle-version }}
job-id: jdk21
gradle-version: wrapper
arguments: |
--no-parallel --no-daemon --scan
build
10 changes: 5 additions & 5 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: 'Set up JDK 11'
uses: actions/setup-java@v4
with:
java-version: 11
java-version: 21
distribution: 'zulu'
- name: 'Start release environment'
run: |
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
- name: 'Set up JDK 11'
uses: actions/setup-java@v4
with:
java-version: 11
java-version: 21
distribution: 'zulu'
- name: 'Start release environment'
run: |
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
- name: 'Set up JDK 11'
uses: actions/setup-java@v4
with:
java-version: 11
java-version: 21
distribution: 'zulu'
- name: 'Start release environment'
run: |
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
- name: 'Set up JDK 8'
uses: actions/setup-java@v4
with:
java-version: 8
java-version: 21
distribution: 'zulu'
- name: 'Start release environment'
run: |
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
- name: 'Set up JDK 8'
uses: actions/setup-java@v4
with:
java-version: 8
java-version: 21
distribution: 'zulu'
- name: 'Start release environment'
run: |
Expand Down
104 changes: 7 additions & 97 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,119 +17,29 @@
import org.gradle.plugins.ide.idea.model.IdeaProject
import org.jetbrains.gradle.ext.CopyrightConfiguration
import org.jetbrains.gradle.ext.ProjectSettings
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
id("com.gradle.plugin-publish") apply false
id("com.github.autostyle")
id("org.jetbrains.gradle.plugin.idea-ext")
id("org.jetbrains.dokka")
`embedded-kotlin`
}

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

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

if (publishToCentral) {
}
val release = providers.gradleProperty("release").getOrElse("false").toBoolean()
val buildVersion = providers.gradleProperty("current.version").get() + if (release) "" else "-SNAPSHOT"

println("Building $buildVersion")
version = buildVersion

allprojects {
group = "com.github.vlsi.gradle"
version = project.findProperty("current.version") as? String ?: rootProject.version

tasks.withType<GenerateModuleMetadata> {
enabled = false
}

plugins.withId("java") {
configure<JavaPluginExtension> {
withSourcesJar()
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(8)
}
}
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
freeCompilerArgs.add("-Xjdk-release=8")
@Suppress("DEPRECATION")
apiVersion.set(KotlinVersion.KOTLIN_1_4)
jvmTarget = JvmTarget.JVM_1_8
}
}
version = buildVersion
}

val licenseHeader = file("gradle/license-header.txt").readText()
allprojects {
if (project.path != ":plugins:license-gather-plugin") {
apply(plugin = "com.github.autostyle")
autostyle {
kotlinGradle {
ktlint {
userData(mapOf("disabled_rules" to "no-wildcard-imports,import-ordering"))
}
trimTrailingWhitespace()
endWithNewline()
}
}
plugins.withId("org.jetbrains.kotlin.jvm") {
autostyle {
kotlin {
licenseHeader(licenseHeader)
trimTrailingWhitespace()
// Generated build/generated-sources/licenses/com/github/vlsi/gradle/license/api/License.kt
// has wrong indentation, and it is not clear how to exclude it
ktlint {
userData(mapOf("disabled_rules" to "no-wildcard-imports,import-ordering"))
}
// It prints errors regarding build/generated-sources/licenses/com/github/vlsi/gradle/license/api/License.kt
// so comment it for now :(
endWithNewline()
}
}
}
}

tasks.withType<AbstractArchiveTask>().configureEach {
// Ensure builds are reproducible
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
dirPermissions {
user {
read = true
write = true
execute = true
}
group {
read = true
write = true
execute = true
}
other {
read = true
execute = true
}
}
filePermissions {
user {
read = true
write = true
}
group {
read = true
write = true
}
other {
read = true
}
}
}
}

fun IdeaProject.settings(configuration: ProjectSettings.() -> kotlin.Unit) =
(this as ExtensionAware).configure(configuration)
Expand Down
25 changes: 18 additions & 7 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

/*
Expand All @@ -20,8 +20,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
*/

plugins {
`java`
`kotlin-dsl` apply false
id("java")
`kotlin-dsl`
id("com.github.autostyle")
}

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

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(11)
}
tasks.withType<KotlinJvmCompile> {
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
jvmTarget = JvmTarget.JVM_11
freeCompilerArgs.add("-Xjdk-release=11")
}
}
}

dependencies {
api("com.github.autostyle:com.github.autostyle.gradle.plugin:4.0")
api("com.gradle.plugin-publish:com.gradle.plugin-publish.gradle.plugin:1.3.1")
api("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$expectedKotlinDslPluginsVersion")
api("org.jetbrains.dokka-javadoc:org.jetbrains.dokka-javadoc.gradle.plugin:2.0.0")
api("com.gradleup.nmcp:com.gradleup.nmcp.gradle.plugin:0.1.5")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin")
subprojects.forEach {
runtimeOnly(project(it.path))
}
Expand Down
35 changes: 35 additions & 0 deletions buildSrc/src/main/kotlin/build.dokka-javadoc.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2019 Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
*
* 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.
*
*/

plugins {
id("java-base")
id("org.jetbrains.dokka-javadoc")
}

java {
// Workaround https://github.com/gradle/gradle/issues/21933, so it adds javadocElements configuration
withJavadocJar()
}

val dokkaJar by tasks.registering(Jar::class) {
group = LifecycleBasePlugin.BUILD_GROUP
description = "Assembles a jar archive containing javadoc"
from(tasks.dokkaGeneratePublicationJavadoc)
archiveClassifier.set("javadoc")
}

configurations[JavaPlugin.JAVADOC_ELEMENTS_CONFIGURATION_NAME].outgoing.artifact(dokkaJar)
50 changes: 50 additions & 0 deletions buildSrc/src/main/kotlin/build.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2019 Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
*
* 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.github.vlsi.gradle.buildtools.filterEolSimple

plugins {
id("java")
id("build.reproducible-timestamps")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}

tasks.withType<JavaCompile>().configureEach {
options.release.set(8)
options.encoding = "UTF-8"
}

tasks.withType<Jar>().configureEach {
into("META-INF") {
filterEolSimple("crlf")
from("$rootDir/LICENSE")
from("$rootDir/NOTICE")
}
manifest {
attributes["Bundle-License"] = "Apache-2.0"
attributes["Specification-Title"] = project.name + " " + project.description
attributes["Specification-Vendor"] = "Vladimir Sitnikov"
attributes["Implementation-Vendor"] = "Vladimir Sitnikov"
attributes["Implementation-Vendor-Id"] = "com.github.vlsi"
// Implementation-Version is not here to make jar reproducible across versions
}
}
Loading
Loading