@@ -142,19 +142,45 @@ if (project.hasProperty(S3_BUCKET_URI_PROPERTY)) {
142
142
}
143
143
}
144
144
145
+ // This is a workaround for https://issues.apache.org/jira/browse/LOG4J2-954,
146
+ // which causes the Log4J2 plugins cache to be overwritten by the last one on the classpath, making it incompatible with a fat jar.
147
+ // There's a similar logic in `corda.common-app`, but we don't want to use OSGi approach in Corda CLI.
148
+ def mergeLog4j2Plugins = tasks. register(' mergeLog4j2Plugins' ) {
149
+ dependsOn configurations. runtimeClasspath
150
+ inputs. files(configurations. runtimeClasspath. collect { it. isDirectory() ? it : zipTree(it) })
151
+ def outputDir = layout. buildDirectory. dir(' log4j' )
152
+ outputs. dir(outputDir)
153
+
154
+ doLast {
155
+ def inputFiles = inputs. files. getFiles(). findAll { it. name == ' Log4j2Plugins.dat' }. collect { it. toURI(). toURL() }
156
+ if (inputFiles) {
157
+ def combinedCache = new org.apache.logging.log4j.core.config.plugins.processor.PluginCache ()
158
+ combinedCache. loadCacheFiles(Collections . enumeration(inputFiles))
159
+ def outputFile = outputDir. get(). file(' META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat' ). asFile
160
+ outputFile. parentFile. mkdirs()
161
+ try (OutputStream out = new FileOutputStream (outputFile)) {
162
+ combinedCache. writeCache(out)
163
+ }
164
+ }
165
+ }
166
+ }
167
+
145
168
jar {
146
169
dependsOn configurations. runtimeClasspath
170
+ dependsOn mergeLog4j2Plugins
171
+
147
172
from { configurations. runtimeClasspath. collect { it. isDirectory() ? it : zipTree(it) } } {
148
173
exclude " META-INF/*.SF"
149
174
exclude " META-INF/*.DSA"
150
175
exclude " META-INF/*.RSA"
151
176
exclude " META-INF/*.EC"
152
177
exclude " META-INF/INDEX.LIST"
153
178
exclude " META-INF/versions/*/module-info.class"
179
+ // Exclude the Log4J2 plugins caches as the merged version is included from mergeLog4J2Plugins
154
180
exclude " META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat"
155
181
exclude " module-info.class"
156
182
}
157
-
183
+ from(mergeLog4j2Plugins)
158
184
159
185
finalizedBy ' cliInstallArchive'
160
186
if (project. hasProperty(S3_BUCKET_URI_PROPERTY )) {
@@ -210,10 +236,3 @@ publishing {
210
236
}
211
237
}
212
238
}
213
-
214
- tasks. named(" installDist" ) {
215
- dependsOn jar
216
- def homePath = System . properties[' user.home' ]
217
- from jar
218
- into " $homePath /.corda/cli/"
219
- }
0 commit comments