-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
executable file
·217 lines (190 loc) · 6.87 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
@file:Suppress("UnstableApiUsage")
import gradlebuild.ZigBuild
import org.gradle.util.internal.VersionNumber
plugins {
id("groovy")
id("java-library")
id("cpp")
id("maven-publish")
id("gradlebuild.git-version")
id("gradlebuild.zig")
id("signing")
}
group = "org.gradle.fileevents"
dependencies {
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
api("net.rubygrapefruit:native-platform:0.22-milestone-26")
implementation("org.slf4j:slf4j-api:1.7.36")
testImplementation(platform("org.junit:junit-bom:5.11.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("ch.qos.logback:logback-classic:1.5.11")
}
java {
toolchain {
// JDK 17 is needed for the `jni_md.h` that allows `JNIEXPORT` to be overriden
languageVersion = JavaLanguageVersion.of(17)
}
// Consumers require Java 8 compatibility
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
// Define a custom configuration that only includes the test sources
val testOnlyClasspath by configurations.creating {
// This configuration extends from 'testImplementation'
extendsFrom(configurations.testImplementation.get())
// Exclude the main source set classes
exclude(group = project.group.toString(), module = project.name)
}
testing {
suites {
// Configure the built-in test suite
val test by getting(JvmTestSuite::class) {
// Use Spock test framework
useSpock("2.2-groovy-3.0")
}
// Test suite for running against a remotely built artifact
val externalTest by registering(JvmTestSuite::class) {
useSpock("2.2-groovy-3.0")
// Use the same source directories as the main test suite
sources {
groovy {
setSrcDirs(listOf("src/test/groovy"))
}
resources {
setSrcDirs(listOf("src/test/resources"))
}
}
// Configure the dependencies
dependencies {
// Use the custom configuration that includes only the test dependencies
implementation(testOnlyClasspath)
// Add the external JAR as a dependency
implementation(fileTree(layout.buildDirectory.dir("remote")) {
include("*.jar")
})
}
}
}
}
// Apply
tasks.javadoc {
exclude("**/internal/**")
}
val compileJava by tasks.named("compileJava", JavaCompile::class) {
options.headerOutputDirectory = layout.buildDirectory.dir("generated/sources/headers/java")
}
sourceSets {
main {
java {
srcDirs(git.javaOutputDir)
}
}
}
zig {
zigVersion = "0.14.0-dev.2254+73f2671c7"
outputDir = layout.buildDirectory.dir("zig")
targets {
create("x86_64-linux-gnu")
create("aarch64-linux-gnu")
create("x86_64-linux-musl")
create("aarch64-linux-musl")
create("x86_64-windows-gnu")
create("aarch64-windows-gnu")
create("x86_64-macos") {
libcFile = layout.projectDirectory.file("libc-macos.txt")
}
create("aarch64-macos") {
libcFile = layout.projectDirectory.file("libc-macos.txt")
}
}
}
zig.targets.configureEach {
optimizer = "ReleaseSmall"
headers.from(compileJava.options.headerOutputDirectory)
sources.from(git.headerOutputDir)
headers.from(layout.projectDirectory.dir("src/main/headers"))
sources.from(layout.projectDirectory.dir("src/main/cpp"))
}
tasks.withType<ZigBuild>().all {
val zigBuild = this
tasks.named<ProcessResources>("processResources") {
into("net/rubygrapefruit/platform") {
into(zigBuild.target) {
from(zigBuild.outputDirectory.dir("out"))
}
}
}
}
fun toMavenVersion(gitVersion: String): Pair<String, Boolean> {
val matcher = Regex("(.*?)(-g[0-9a-f]+)?(-dirty)?").matchEntire(gitVersion) ?: error("Invalid version: $gitVersion")
val version = VersionNumber.parse(matcher.groupValues[1])
// TODO Prevent publishing dirty stuff?
// If it's not a tagged version, or if there are local changes, this is a snapshot
val snapshot = matcher.groupValues[2].isNotEmpty() || matcher.groupValues[3].isNotEmpty()
val mavenVersion = if (snapshot) {
VersionNumber(version.major, version.minor + 1, 0, "SNAPSHOT").toString()
} else {
version.toString()
}
return Pair(mavenVersion, snapshot)
}
val (mavenVersion, snapshot) = toMavenVersion(project.version.toString())
println("Building version $mavenVersion to ${if (snapshot) "snapshot" else "release"} repository (Git version: ${project.version})")
publishing {
repositories {
maven {
val artifactoryUrl = providers.environmentVariable("GRADLE_INTERNAL_REPO_URL").orNull
val artifactoryUsername = providers.environmentVariable("ORG_GRADLE_PROJECT_publishUserName").orNull
val artifactoryPassword = providers.environmentVariable("ORG_GRADLE_PROJECT_publishApiKey").orNull
name = "remote"
val libsType = if (snapshot) "snapshots" else "releases"
url = uri("${artifactoryUrl}/libs-${libsType}-local")
credentials {
username = artifactoryUsername
password = artifactoryPassword
}
}
}
publications {
create<MavenPublication>("library") {
from(components["java"])
groupId = project.group.toString()
artifactId = project.name
version = mavenVersion
description = project.description
pom {
packaging = "jar"
url = "https://github.com/gradle/gradle-fileevents"
licenses {
license {
name = "Apache-2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
name = "The Gradle team"
organization = "Gradle Inc."
organizationUrl = "https://gradle.org"
}
}
scm {
connection = "scm:git:git://github.com/gradle/gradle-fileevents.git"
developerConnection = "scm:git:ssh://github.com:gradle/gradle-fileevents.git"
url = "https://github.com/gradle/gradle-fileevents"
}
}
}
}
}
signing {
useInMemoryPgpKeys(
System.getenv("PGP_SIGNING_KEY"),
System.getenv("PGP_SIGNING_KEY_PASSPHRASE")
)
if (!System.getenv("PGP_SIGNING_KEY_PASSPHRASE").isNullOrBlank()) {
publishing.publications.configureEach {
signing.sign(this)
}
}
}