-
Notifications
You must be signed in to change notification settings - Fork 282
/
build.gradle.kts
278 lines (238 loc) · 8.38 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import io.github.qupath.gradle.PlatformPlugin
plugins {
id("qupath.common-conventions")
id("qupath.javafx-conventions")
id("qupath.git-commit-id")
id("qupath.djl-conventions")
id("qupath.jpackage-conventions")
id("qupath.license-conventions")
`version-catalog`
`maven-publish`
}
/*
* Fail early if the operating system or JDK isn't compatible
*/
if (io.github.qupath.gradle.Utils.currentPlatform() == PlatformPlugin.Platform.UNKNOWN) {
throw GradleException("Unknown operating system - can't build QuPath, sorry!")
}
if ("32" == System.getProperty("sun.arch.data.model")) {
throw GradleException("Can't build QuPath using a 32-bit JDK - please use a 64-bit JDK instead")
}
/*
* Get the current QuPath version
*/
val qupathVersion = rootProject.version.toString()
/**
* Set the group
*/
base {
group = "io.github.qupath"
}
/*
* Get version catalog
*/
catalog {
versionCatalog {
from(files("./gradle/libs.versions.toml"))
// Include version for the current jars in the version catalog, as they will be useful in extensions
version("qupath", qupathVersion)
library("qupath.gui.fx", group.toString(), project(":qupath-gui-fx").name).versionRef("qupath")
library("qupath.core", group.toString(), project(":qupath-core").name).versionRef("qupath")
library("qupath.core.processing", group.toString(), project(":qupath-core-processing").name).versionRef("qupath")
bundle("qupath", listOf("qupath.gui.fx", "qupath.core", "qupath.core.processing"))
}
}
/*
* Publish catalog to help with dependency management across extensions
*/
publishing {
repositories {
maven {
name = "SciJava"
val releasesRepoUrl = uri("https://maven.scijava.org/content/repositories/releases")
val snapshotsRepoUrl = uri("https://maven.scijava.org/content/repositories/snapshots")
// Use gradle -Prelease publish
url = if (project.hasProperty("release")) releasesRepoUrl else snapshotsRepoUrl
credentials {
username = System.getenv("MAVEN_USER")
password = System.getenv("MAVEN_PASS")
}
}
}
publications {
create<MavenPublication>("maven") {
artifactId = "qupath-catalog"
version = qupathVersion
from(components["versionCatalog"])
}
}
}
/**
* Generate a single Javadoc for all projects.
*/
// See https://discuss.gradle.org/t/best-approach-gradle-multi-module-project-generate-just-one-global-javadoc/18657
tasks.register<Javadoc>("mergedJavadocs") {
source = sourceSets.main.get().allJava
description = "Generate merged javadocs for all projects"
group = "Documentation"
val dest = layout.buildDirectory.dir("docs-merged/javadoc").get().asFile
setDestinationDir(dest)
title = "QuPath ${gradle.extra["qupath.app.version"]}"
// Don't fail on error - this happened too often due to a javadoc link being temporarily down
isFailOnError = false
}
/**
* Export icons and a command list based on menu items (useful for documentation).
* Note that this requires JavaFX to be available.
*/
tasks.register<JavaExec>("exportDocs") {
description = "Export icons and command descriptions for documentation"
group = "QuPath"
val docsDir = layout.buildDirectory.dir("qupath-docs").get().asFile
// Note we need all subprojects to ensure icons & commands are also loaded from extensions
dependencies {
subprojects.forEach(::implementation)
}
doFirst {
println("Making docs dir in ${docsDir.absolutePath}")
docsDir.mkdirs()
}
classpath = sourceSets["main"].runtimeClasspath
mainClass = "qupath.lib.gui.tools.DocGenerator"
args = listOf(docsDir.absolutePath, "--all")
}
/**
* Determine which projects to include/exclude as dependencies
*/
val excludedProjects = listOf(project)
val includedProjects = rootProject.subprojects.filter { !excludedProjects.contains(it) }
dependencies {
includedProjects.forEach {
implementation(it)
}
with (gradle.extra["qupath.included.dependencies"] as List<*>) {
forEach {
if (it != null)
implementation(it)
}
}
implementation(libs.picocli)
implementation(extraLibs.bundles.extensions) {
// We don't want to bring in snapshot versions
exclude(group=group)
}
}
application {
mainClass = "qupath.QuPath"
val qupathAppName = gradle.extra["qupath.app.name"] as String
applicationName = qupathAppName
applicationDefaultJvmArgs = listOf(gradle.extra["qupath.jvm.args"] as String)
// Necessary when using ./gradlew run to support style manager to change themes
applicationDefaultJvmArgs += "--add-opens"
applicationDefaultJvmArgs += "javafx.graphics/com.sun.javafx.css=ALL-UNNAMED"
// Necessary when using ./gradlew run to support project metadata autocomplete
// See https://github.com/controlsfx/controlsfx/issues/1505
applicationDefaultJvmArgs += "--add-opens"
applicationDefaultJvmArgs += "javafx.base/com.sun.javafx.event=ALL-UNNAMED"
}
/**
* Copies the Javadoc jars to a directory for access within QuPath
*/
tasks.register<Copy>("assembleJavadocs") {
group = "documentation"
description = "Copies the Javadoc jars to a directory for access within QuPath"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// Always include jars developed by all subprojects
rootProject.subprojects.forEach {
from(it.tasks.javadocJar)
}
// Also include selected dependency jars
val dependenciesJavadoc = dependencies.createArtifactResolutionQuery()
.forComponents(configurations
.runtimeClasspath
.get()
.incoming
.resolutionResult
.allDependencies
.filterIsInstance<ResolvedDependencyResult>()
.map { it.selected.id }
)
.withArtifacts(JvmLibrary::class, SourcesArtifact::class, JavadocArtifact::class)
.execute()
.resolvedComponents
.map {
c -> c.getArtifacts(JavadocArtifact::class)
.filterIsInstance<ResolvedArtifactResult>()
.map {it.file}
}
.flatten()
.filter {
val docs = findProperty("docs") ?: "default"
when (docs) {
"all" -> return@filter true
"none" -> return@filter false
"qupath" -> return@filter it.name.startsWith("qupath")
else -> return@filter it.name.startsWith("qupath") ||
it.name.startsWith("jts") || it.name.startsWith("ij")
}
}
dependenciesJavadoc.forEach {
from(it)
}
into(layout.buildDirectory.dir("javadocs"))
}
tasks.distZip {
enabled = false
}
tasks.distTar {
enabled = false
}
tasks.installDist {
dependsOn("assembleJavadocs")
}
tasks.startScripts {
dependsOn("generateLicenseReport")
}
/**
* Copy key files into the distribution
*/
distributions {
main {
contents {
// We need a DuplicatesStrategy if settings.gradle.kts uses includeFlat for extra extensions
// (which require QuPath as a dependency)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
into("lib") {
from(rootDir)
include("CHANGELOG.md")
include("STARTUP.md")
include("LICENSE")
}
// Get the core licenses associated with the app
into("lib") {
from(".")
include("licenses/**")
}
// Check if we have licenses stored with other extensions,
// either directly in the project directory or under "resources"
into("lib") {
includedProjects.forEach {
from(it.projectDir)
from(File(it.projectDir, "src/main/resources"))
include("licenses/**")
includeEmptyDirs = false
}
}
// Copy license report
into("lib/licenses") {
from(layout.buildDirectory.dir("reports/dependency-license"))
include("THIRD-PARTY.txt")
}
// Copy javadocs
into("lib/docs") {
from(layout.buildDirectory.dir("javadocs").get())
include("*.jar")
}
}
}
}