-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
155 lines (133 loc) · 5.98 KB
/
build.gradle.kts
File metadata and controls
155 lines (133 loc) · 5.98 KB
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
import groovy.xml.XmlSlurper
import groovy.xml.slurpersupport.GPathResult
import groovy.xml.slurpersupport.NodeChild
import java.io.ByteArrayOutputStream
plugins {
`java-platform`
`version-catalog`
`maven-publish`
// id("org.gradlex.java-ecosystem-capabilities-base") // only rules
// id("org.gradlex.logging-capabilities") // logging extension
}
layout.buildDirectory = layout.projectDirectory.asFile.parentFile.resolve("target/gradle")
group = "org.scijava"
version = File("../pom.xml")
.readText()
.substringAfter("<artifactId>pom-scijava<")
.substringAfter("<version>")
.substringBefore('<')
javaPlatform {
allowDependencies()
}
val computeCatalogAndPlatform = tasks.register<Exec>("generateCatalog") {
workingDir = projectDir.parentFile
commandLine("sh", "-c", "mvn -B -Dfile.encoding=UTF-8 -f pom.xml help:effective-pom")
standardOutput = ByteArrayOutputStream()
doLast {
var output = standardOutput.toString()
// Remove leading/trailing maven output from pom.xml
output = output
.substringAfter("Effective POMs, after inheritance, interpolation, and profiles are applied:")
.substringBefore("[INFO]")
.trim()
operator fun GPathResult.div(child: String) = children().find { (it!! as NodeChild).name() == child } as GPathResult
val xml = XmlSlurper().parseText(output)
val deps = xml / "dependencyManagement" / "dependencies"
val bundles = mutableMapOf<String, ArrayList<String>>()
val skip = listOf("mpicbg" to "mpicbg_")
val cache = mutableSetOf<String>() // skip duplicates, such as org.bytedeco:ffmpeg
for (dep in deps.children()) {
val node = dep as NodeChild
val g = node / "groupId"
val a = node / "artifactId"
val v = node / "version"
val gav = "$g:$a:$v"
if (("$g" to "$a") in skip || gav in cache)
continue
cache += gav
val camel = "$a".split('-', '_')
.joinToString("") { if (it.isEmpty()) "" else it[0].uppercase() + it.substring(1).lowercase() }
.replaceFirstChar { it.lowercase() }
fun getAlias(group: String): String {
val alias = "$group." + when {
camel.startsWith(group) -> camel.substringAfter(group).replaceFirstChar { it.lowercase() }.ifEmpty { group }
else -> camel
}
bundles.getOrPut(group, ::ArrayList) += alias
return alias
}
val lastWordAsGroup = listOf("org.scijava", "net.imagej", "net.imglib2", "sc.fiji", "org.janelia.saalfeldlab")
val alias = when ("$g") {
in lastWordAsGroup -> getAlias(g.toString().substringAfterLast('.'))
"io.scif" -> getAlias("scifio")
else -> "$g.$camel"
}
catalog.versionCatalog { library(alias, gav) }
dependencies {
constraints {
val ga = "$g:$a"
if (ga in runtimeDeps || jogampNatives.any { it.startsWith(ga) })
runtime(gav) //.also { println("runtime($dep)") }
else
api(gav) //.also{ println("api($dep)") }
}
}
}
for ((alias, aliases) in bundles)
catalog.versionCatalog { bundle(alias, aliases) }
}
}
publishing {
publications {
repositories {
maven {
name = "sciJava"
// credentials(PasswordCredentials::class)
// url = uri("https://maven.scijava.org/content/repositories/releases")
url = uri("repo")
}
}
create<MavenPublication>("pomScijava") {
from(components["javaPlatform"])
// from(components["versionCatalog"])
}
}
}
val versionCatalogElements by configurations
val javaPlatform by components.existing {
this as AdhocComponentWithVariants
addVariantsFromConfiguration(versionCatalogElements) {}
}
tasks {
// dependsOn runs only if the src is successful, finalizedBy not
generateCatalogAsToml { dependsOn(computeCatalogAndPlatform) }
val generateMetadataFileForPomScijavaPublication by getting { dependsOn(computeCatalogAndPlatform) }
register("generateCatalogAndPlatform") { dependsOn(generateMetadataFileForPomScijavaPublication, generateCatalogAsToml) }
}
val runtimeDeps = listOf("org.antlr:antlr-runtime",
"xalan:serializer",
"xalan:xalan",
"com.github.vbmacher:java-cup-runtime",
"nz.ac.waikato.cms.weka.thirdparty:java-cup-11b-runtime",
"org.jogamp.gluegen:gluegen-rt-main",
"org.jogamp.gluegen:gluegen-rt",
"org.jogamp.joal:joal",
"org.jogamp.jocl:jocl",
"org.jogamp.jogl:jogl-all-main",
"org.jogamp.jogl:jogl-all",
"org.jogamp.jogl:jogl-all-noawt",
"com.nativelibs4java:bridj",
"org.bytedeco:ffmpeg",
"org.bytedeco:hdf5",
"org.bytedeco:leptonica",
"org.bytedeco:openblas",
"org.bytedeco:opencv",
"org.bytedeco:tesseract",
"org.jline:jline-native",
"com.github.jnr:jffi",
"org.jzy3d:jzy3d-native-jogl-awt",
"org.jzy3d:jzy3d-native-jogl-swing")
val jogampNatives = listOf("org.jogamp.gluegen:gluegen-rt-natives-",
"org.jogamp.jogl:jogl-all-natives-",
"org.jogamp.gluegen:gluegen-rt-natives-",
"org.jogamp.jogl:jogl-all-natives-")