@@ -94,15 +94,26 @@ application {
94
94
archivesBaseName = ' spotless-cli'
95
95
}
96
96
97
+
98
+ def nativeCompileMetaDir = project. layout. buildDirectory. dir(' nativeCompile/src/main/resources/native-image/' + project. group + ' /' + project. name)
99
+
97
100
// use tasks 'nativeCompile' and 'nativeRun' to compile and run the native image
98
101
graalvmNative {
99
102
agent {
100
103
enabled = true
101
104
defaultMode = " standard"
102
105
metadataCopy {
103
106
inputTaskNames. add(' test' )
104
- mergeWithExisting = true
107
+ mergeWithExisting = false
108
+ outputDirectories. add(nativeCompileMetaDir. get(). asFile. path)
105
109
}
110
+ tasksToInstrumentPredicate = new java.util.function.Predicate<Task > () {
111
+ @Override
112
+ boolean test (Task task ) {
113
+ println (" Instrumenting task: " + task. name + " " + task. name == ' test' )
114
+ return task. name == ' test'
115
+ }
116
+ }
106
117
}
107
118
binaries {
108
119
main {
@@ -130,12 +141,38 @@ graalvmNative {
130
141
}
131
142
}
132
143
144
+
145
+ tasks. named(' metadataCopy' ) {
146
+ dependsOn(' test' )
147
+ }
148
+
133
149
tasks. named(' nativeCompile' ) {
134
150
dependsOn(' shadowJar' )
135
151
classpathJar = tasks. shadowJar. archiveFile. get(). asFile
136
152
}
137
153
154
+
155
+ tasks. named(' shadowJar' , com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar ) {
156
+ dependsOn(' metadataCopy' ) // produces graalvm agent info
157
+ from(nativeCompileMetaDir. get(). asFile. path) {
158
+ into(' META-INF/native-image/' + project. group + ' /' + project. name)
159
+ }
160
+ }
161
+
162
+ gradle. taskGraph. whenReady { graph ->
163
+ if (graph. hasTask(' nativeCompile' ) || graph. hasTask(' metadataCopy' ) || graph. hasTask(' shadowJar' )) {
164
+ // enable graalvm agent using property here instead of command line `-Pagent=standard`
165
+ // this collects information about reflective access and resources used by the application (e.g. GJF)
166
+ project. property(' agent' , ' standard' )
167
+ }
168
+ }
169
+
138
170
tasks. withType(Test ). configureEach {
171
+ if (it. name == ' test' ) {
172
+ if (project. hasProperty(' agent' )) {
173
+ it. inputs. property(' agent' , project. property(' agent' )) // make sure to re-run tests if agent changes
174
+ }
175
+ }
139
176
if (it. name == ' testCliProcess' ) {
140
177
it. dependsOn(' shadowJar' )
141
178
it. systemProperty ' spotless.cli.shadowJar' , tasks. shadowJar. archiveFile. get(). asFile
0 commit comments