File size: 3,193 Bytes
1eff9b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import org.gradle.api.tasks.bundling.AbstractArchiveTask
import java.security.MessageDigest

plugins {
    `java-library`
    `maven-publish`
    signing
}

group = "org.ortho32"
version = "0.1.0"

subprojects {
    apply(plugin = "java-library")
    apply(plugin = "maven-publish")
    apply(plugin = "signing")

    group = rootProject.group
    version = rootProject.version

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

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

    tasks.withType<Javadoc> {
        options.encoding = "UTF-8"
    }

    tasks.withType<AbstractArchiveTask> {
        isPreserveFileTimestamps = false
        isReproducibleFileOrder = true
        dirPermissions { unix("0755") }
        filePermissions { unix("0644") }
    }

    tasks.withType<Jar> {
        manifest {
            attributes(
                "Implementation-Title" to project.name,
                "Implementation-Version" to project.version,
                "Implementation-Vendor" to "ORTHO-32"
            )
        }
    }

    repositories {
        mavenCentral()
    }

    // JUnit BOM available to every module
    dependencies {
        "testImplementation"(platform("org.junit:junit-bom:5.11.0"))
        "testImplementation"("org.junit.jupiter:junit-jupiter")
        "testRuntimeOnly"("org.junit.platform:junit-platform-launcher")
    }

    tasks.test {
        useJUnitPlatform()
        testLogging { events("passed", "skipped", "failed") }
    }

    publishing {
        publications {
            create<MavenPublication>("maven") {
                from(components["java"])
                pom {
                    name.set("ORTHO-32 ${project.name}")
                    description.set("ORTHO-32 Java SDK - ${project.name}")
                    url.set("https://github.com/ortho32/ortho32-sdk-java")
                    licenses {
                        license {
                            name.set("Apache-2.0")
                            url.set("https://www.apache.org/licenses/LICENSE-2.0")
                        }
                    }
                }
            }
        }
    }

    // Checksum generation for reproducible builds
    tasks.register("generateChecksums") {
        group = "verification"
        description = "Generate SHA-256 checksums for all JAR artifacts"
        dependsOn(tasks.named("build"))
        doLast {
            val digest = MessageDigest.getInstance("SHA-256")
            fileTree(layout.buildDirectory.dir("libs")).forEach { file ->
                if (file.isFile && file.extension == "jar") {
                    val hash = digest.digest(file.readBytes()).joinToString("") { "%02x".format(it) }
                    val checksumFile = file.resolveSibling("${file.name}.sha256")
                    checksumFile.writeText("$hash  ${file.name}\n")
                }
            }
        }
    }
    tasks.named("build") { finalizedBy("generateChecksums") }

    // Dependency locking
    dependencyLocking {
        lockAllConfigurations()
    }
}