You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's really annoying that this does not work without custom code, the sbt-assembly-log4j2 plugin does not work with the new version of the sbt-assembly plugin so here's my contribution for everyone encountering this problem.
assembly / assemblyMergeStrategy := {
case PathList(ps@_*) if ps.last equalsIgnoreCase "Log4j2Plugins.dat" =>
import java.io.FileInputStream
import java.io.FileOutputStream
import org.apache.logging.log4j.core.config.plugins.processor.PluginCache
import scala.collection.JavaConverters.asJavaEnumerationConverter
import sbt.io.{ IO, Using }
import sbtassembly.Assembly.Dependency
CustomMergeStrategy("Log4j2Plugins") {
conflicts =>
val dependencyStreamResource = Using.resource((dependency: Dependency) => dependency.stream())
val tempDir = "target/log4j2-plugin-cache"
val urls = conflicts
.map { conflict =>
dependencyStreamResource(conflict) { is =>
val file = new File(s"$tempDir/${conflict.module.get.jarName}-Log4j2Plugins.dat")
IO.write(file, IO.readBytes(is))
file.toURI.toURL
}
}
val aggregator = new PluginCache()
aggregator.loadCacheFiles(urls.toIterator.asJavaEnumeration)
val pluginCache = new File(s"$tempDir/Log4j2Plugins.dat")
val pluginCacheOutputStream = new FileOutputStream(pluginCache)
aggregator.writeCache(pluginCacheOutputStream)
pluginCacheOutputStream.close()
Right(Vector(JarEntry(conflicts.head.target, () => new FileInputStream(pluginCache))))
}
case x =>
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
}
The text was updated successfully, but these errors were encountered:
It's really annoying that this does not work without custom code, the sbt-assembly-log4j2 plugin does not work with the new version of the sbt-assembly plugin so here's my contribution for everyone encountering this problem.
The text was updated successfully, but these errors were encountered: