-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
186 lines (162 loc) · 5.59 KB
/
build.gradle
File metadata and controls
186 lines (162 loc) · 5.59 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
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
plugins {
id 'java-library'
id 'maven-publish'
id 'org.graalvm.buildtools.native' version '0.10.6'
}
repositories {
mavenLocal()
maven {
url = uri('https://s01.oss.sonatype.org/content/repositories/releases/')
}
maven {
url = uri('https://s01.oss.sonatype.org/content/repositories/snapshots/')
}
mavenCentral()
}
group = 'org.restheart'
version = '1.0.0-SNAPSHOT'
description = 'restheart-plugin-skeleton'
def restheartVersion = [9.0.0,9.1000.0)
// Profile-based configurations
// When -Pname is passed, the property exists (even if empty)
def nativeProfile = project.hasProperty('native')
def securityProfile = project.hasProperty('security')
def mongodbProfile = project.hasProperty('mongodb')
def graphqlProfile = project.hasProperty('graphql')
def mongoclientProviderProfile = project.hasProperty('mongoclient-provider')
def metricsProfile = project.hasProperty('metrics')
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}
dependencies {
// Runtime dependency
implementation 'org.apache.commons:commons-lang3:3.18.0'
// Base provided dependency
if (nativeProfile) {
implementation "org.restheart:restheart-commons:${restheartVersion}"
implementation "org.restheart:restheart:${restheartVersion}"
implementation "org.restheart:restheart-polyglot:${restheartVersion}"
// Update transitive dependency of undertow-core required for the native image build
implementation 'org.wildfly.common:wildfly-common:1.7.0.Final'
} else {
compileOnly "org.restheart:restheart-commons:${restheartVersion}"
}
// Profile-based dependencies
if (securityProfile) {
implementation "org.restheart:restheart-security:${restheartVersion}"
}
if (mongodbProfile) {
implementation "org.restheart:restheart-mongodb:${restheartVersion}"
}
if (graphqlProfile) {
implementation "org.restheart:restheart-graphql:${restheartVersion}"
}
if (mongoclientProviderProfile) {
implementation "org.restheart:restheart-mongoclient-provider:${restheartVersion}"
}
if (metricsProfile) {
implementation "org.restheart:restheart-metrics:${restheartVersion}"
}
}
// Configure clean to remove target directory
tasks.named('clean') {
delete "$rootDir/target"
}
tasks.named('jar') {
// Set the final jar name
archiveBaseName = 'restheart-plugin-skeleton'
archiveVersion = ''
destinationDirectory = file("$rootDir/target")
// Always set Main-Class for native builds
manifest {
attributes(
'Main-Class': 'org.restheart.Bootstrapper',
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Build-Time': new Date().toInstant().toString()
)
}
}
// Task to copy runtime dependencies to target/lib
tasks.register('copyDependencies', Copy) {
from configurations.runtimeClasspath
into "$rootDir/target/lib"
}
// Make build depend on copyDependencies
tasks.named('build') {
dependsOn copyDependencies
}
// When native profile is active, make build depend on nativeCompile
// Must be done in afterEvaluate because nativeCompile is created by the GraalVM plugin
afterEvaluate {
if (nativeProfile) {
tasks.named('build').configure {
dependsOn tasks.named('nativeCompile')
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release = 24
}
tasks.withType(Javadoc).configureEach {
options.encoding = 'UTF-8'
}
// Native image configuration
if (nativeProfile) {
def nativeGc = findProperty('native.gc') ?: '--gc=serial'
def nativeQuickBuild = findProperty('native.quickBuild') == null ? true : findProperty('native.quickBuild').toBoolean()
graalvmNative {
binaries {
main {
imageName = 'restheart-plugin-skeleton'
mainClass = 'org.restheart.Bootstrapper'
sharedLibrary = false
buildArgs.add(nativeGc)
buildArgs.add('--no-fallback')
quickBuild = nativeQuickBuild
}
}
}
tasks.named('nativeCompile') {
doLast {
def outputDir = file("$rootDir/target")
outputDir.mkdirs()
// Copy the native image to target directory
def buildDir = file("$rootDir/build/native/nativeCompile")
def nativeExe = file("$buildDir/restheart-plugin-skeleton")
// Also check for dylib on macOS or exe on Windows
if (!nativeExe.exists()) {
nativeExe = file("$buildDir/restheart-plugin-skeleton.dylib")
}
if (!nativeExe.exists()) {
nativeExe = file("$buildDir/restheart-plugin-skeleton.exe")
}
if (nativeExe.exists()) {
def targetName = nativeExe.name.replace('.dylib', '').replace('.exe', '')
def targetExe = file("$rootDir/target/$targetName")
copy {
from nativeExe
into outputDir
rename { targetName }
}
// Make executable
targetExe.setExecutable(true)
println "Native image copied to: $targetExe"
} else {
println "Warning: Native image not found in $buildDir"
}
// Create plugins directory
file("$rootDir/target/plugins").mkdirs()
}
}
}
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
}