From e5a3f7c35667c6c3bcca859e8134519e5745d307 Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Wed, 29 Sep 2021 12:26:46 +0200 Subject: [PATCH 1/2] Add a "slim" deployment option. As the shaded version is the default version and we can't suddenly not shade by default, we need to jump through some loops. Note: A solution using a classifier was discarded as it would require two different poms (a normal one and the dependency-reduced one for the shades) and this is strongly discouraged. - The artifactId is concatened with a `deploymentType` property which is by default empty - Native image properties files are duplicated (there is no good transformer for them), one includes the fully qualified names of the original resources, the other one of the shaded ones - The shaded ones are excluded by default from the resources - `maven-shade-plugin` has been moved into a profile that is active unless `skipShade` is true - `maven-shade-plugin` will exclude the non-shaded native shims and include the shaded ones now - The slim profile will be activated when shading is deactived, setting deploymentType to `slim` For the final deployment via CI something like this will be necesssary (two steps) Deploy driver and the rest as used to: ``` mvn clean deploy ``` Deploy the slim version only ``` mvn -DskipShade -pl org.neo4j.driver:neo4j-java-driver clean deploy ``` --- driver/pom.xml | 141 ++++++++++++------ .../neo4j-java-driver/native-image.properties | 28 ++-- .../neo4j-java-driver/reflection-config.json | 20 +-- .../neo4j-java-driver/native-image.properties | 20 +++ .../neo4j-java-driver/reflection-config.json | 58 +++++++ 5 files changed, 199 insertions(+), 68 deletions(-) create mode 100644 driver/src/main/resources/shaded/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties create mode 100644 driver/src/main/resources/shaded/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflection-config.json diff --git a/driver/pom.xml b/driver/pom.xml index 7bd9ca1a63..3251f5c293 100644 --- a/driver/pom.xml +++ b/driver/pom.xml @@ -10,7 +10,7 @@ .. - neo4j-java-driver + neo4j-java-driver${deploymentType} jar Neo4j Java Driver @@ -22,6 +22,7 @@ org.neo4j.driver ${project.basedir}/.. false + @@ -82,7 +83,102 @@ + + + slim + + + skipShade + true + + + + -slim + + + + + shading + + + skipShade + !true + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + io.netty:* + io.projectreactor:* + + + + + io.netty + org.neo4j.driver.internal.shaded.io.netty + + + reactor + org.neo4j.driver.internal.shaded.reactor + + + + + + src/main/resources/shaded/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties + META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties + + + src/main/resources/shaded/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflection-config.json + META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflection-config.json + + + + + io.netty:* + + META-INF/native-image/** + + + + + org.neo4j.driver:neo4j-java-driver + + META-INF/native-image/** + + + + true + true + + + + + + + + + + + + src/main/resources + + shaded/**/* + + + org.codehaus.mojo @@ -215,49 +311,6 @@ ${project.build.directory}/classes - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - - - io.netty:* - io.projectreactor:* - - - - - io.netty - org.neo4j.driver.internal.shaded.io.netty - - - reactor - org.neo4j.driver.internal.shaded.reactor - - - - - - - - io.netty:* - - META-INF/native-image/** - - - - true - true - - - - diff --git a/driver/src/main/resources/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties b/driver/src/main/resources/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties index c2b3de8823..9d2171e945 100644 --- a/driver/src/main/resources/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties +++ b/driver/src/main/resources/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties @@ -2,19 +2,19 @@ Args = -H:ReflectionConfigurationResources=${.}/reflection-config.json \ --initialize-at-run-time=org.neo4j.driver.internal.async.connection.BoltProtocolUtil \ --initialize-at-run-time=org.neo4j.driver.internal.async.connection.ChannelAttributes \ --initialize-at-run-time=org.neo4j.driver.internal.async.connection.ChannelConnectedListener \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.ByteBufAllocator \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.ByteBufUtil \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.ByteBufUtil$HexUtil \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.PooledByteBufAllocator \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.UnpooledHeapByteBuf \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.UnreleasableByteBuf \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.handler.ssl.Conscrypt \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.handler.ssl.ConscryptAlpnSslEngine \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslEngine \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.handler.ssl.util.ThreadLocalInsecureRandom \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.util.AbstractReferenceCounted \ - --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.util.internal.logging.Log4JLogger \ + --initialize-at-run-time=io.netty.buffer.AbstractReferenceCountedByteBuf \ + --initialize-at-run-time=io.netty.buffer.ByteBufAllocator \ + --initialize-at-run-time=io.netty.buffer.ByteBufUtil \ + --initialize-at-run-time=io.netty.buffer.ByteBufUtil$HexUtil \ + --initialize-at-run-time=io.netty.buffer.PooledByteBufAllocator \ + --initialize-at-run-time=io.netty.buffer.UnpooledHeapByteBuf \ + --initialize-at-run-time=io.netty.buffer.UnreleasableByteBuf \ + --initialize-at-run-time=io.netty.handler.ssl.Conscrypt \ + --initialize-at-run-time=io.netty.handler.ssl.ConscryptAlpnSslEngine \ + --initialize-at-run-time=io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator \ + --initialize-at-run-time=io.netty.handler.ssl.ReferenceCountedOpenSslEngine \ + --initialize-at-run-time=io.netty.handler.ssl.util.ThreadLocalInsecureRandom \ + --initialize-at-run-time=io.netty.util.AbstractReferenceCounted \ + --initialize-at-run-time=io.netty.util.internal.logging.Log4JLogger \ -Dio.netty.noUnsafe=true \ -Dio.netty.leakDetection.level=DISABLED diff --git a/driver/src/main/resources/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflection-config.json b/driver/src/main/resources/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflection-config.json index 68572f10fb..97033e8c9e 100644 --- a/driver/src/main/resources/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflection-config.json +++ b/driver/src/main/resources/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflection-config.json @@ -1,56 +1,56 @@ [ { - "name": "org.neo4j.driver.internal.shaded.io.netty.channel.socket.nio.NioSocketChannel", + "name": "io.netty.channel.socket.nio.NioSocketChannel", "methods": [ { "name": "", "parameterTypes": [] } ] }, { - "name": "org.neo4j.driver.internal.shaded.io.netty.channel.socket.nio.NioServerSocketChannel", + "name": "io.netty.channel.socket.nio.NioServerSocketChannel", "methods": [ { "name": "", "parameterTypes": [] } ] }, { - "name" : "org.neo4j.driver.internal.shaded.io.netty.buffer.AbstractByteBufAllocator", + "name" : "io.netty.buffer.AbstractByteBufAllocator", "allDeclaredMethods" : true }, { - "name" : "org.neo4j.driver.internal.shaded.io.netty.util.ReferenceCountUtil", + "name" : "io.netty.util.ReferenceCountUtil", "allDeclaredMethods" : true }, { - "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerIndexField", + "name" : "io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerIndexField", "fields": [ {"name": "producerIndex", "allowUnsafeAccess": true} ] }, { - "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerLimitField", + "name" : "io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerLimitField", "fields": [ {"name": "producerLimit", "allowUnsafeAccess": true} ] }, { - "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueConsumerIndexField", + "name" : "io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueConsumerIndexField", "fields": [ {"name": "consumerIndex", "allowUnsafeAccess": true} ] }, { - "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueProducerFields", + "name" : "io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueProducerFields", "fields": [ {"name": "producerIndex", "allowUnsafeAccess": true} ] }, { - "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields", + "name" : "io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields", "fields": [ {"name": "producerLimit", "allowUnsafeAccess": true} ] }, { - "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields", + "name" : "io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields", "fields": [ {"name": "consumerIndex", "allowUnsafeAccess": true} ] diff --git a/driver/src/main/resources/shaded/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties b/driver/src/main/resources/shaded/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties new file mode 100644 index 0000000000..c2b3de8823 --- /dev/null +++ b/driver/src/main/resources/shaded/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties @@ -0,0 +1,20 @@ +Args = -H:ReflectionConfigurationResources=${.}/reflection-config.json \ + --initialize-at-run-time=org.neo4j.driver.internal.async.connection.BoltProtocolUtil \ + --initialize-at-run-time=org.neo4j.driver.internal.async.connection.ChannelAttributes \ + --initialize-at-run-time=org.neo4j.driver.internal.async.connection.ChannelConnectedListener \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.ByteBufAllocator \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.ByteBufUtil \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.ByteBufUtil$HexUtil \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.PooledByteBufAllocator \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.UnpooledHeapByteBuf \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.buffer.UnreleasableByteBuf \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.handler.ssl.Conscrypt \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.handler.ssl.ConscryptAlpnSslEngine \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslEngine \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.handler.ssl.util.ThreadLocalInsecureRandom \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.util.AbstractReferenceCounted \ + --initialize-at-run-time=org.neo4j.driver.internal.shaded.io.netty.util.internal.logging.Log4JLogger \ + -Dio.netty.noUnsafe=true \ + -Dio.netty.leakDetection.level=DISABLED diff --git a/driver/src/main/resources/shaded/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflection-config.json b/driver/src/main/resources/shaded/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflection-config.json new file mode 100644 index 0000000000..68572f10fb --- /dev/null +++ b/driver/src/main/resources/shaded/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflection-config.json @@ -0,0 +1,58 @@ +[ + { + "name": "org.neo4j.driver.internal.shaded.io.netty.channel.socket.nio.NioSocketChannel", + "methods": [ + { "name": "", "parameterTypes": [] } + ] + }, + { + "name": "org.neo4j.driver.internal.shaded.io.netty.channel.socket.nio.NioServerSocketChannel", + "methods": [ + { "name": "", "parameterTypes": [] } + ] + }, + { + "name" : "org.neo4j.driver.internal.shaded.io.netty.buffer.AbstractByteBufAllocator", + "allDeclaredMethods" : true + }, + { + "name" : "org.neo4j.driver.internal.shaded.io.netty.util.ReferenceCountUtil", + "allDeclaredMethods" : true + }, + { + "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerIndexField", + "fields": [ + {"name": "producerIndex", "allowUnsafeAccess": true} + ] + }, + { + "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerLimitField", + "fields": [ + {"name": "producerLimit", "allowUnsafeAccess": true} + ] + }, + { + "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueConsumerIndexField", + "fields": [ + {"name": "consumerIndex", "allowUnsafeAccess": true} + ] + }, + { + "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueProducerFields", + "fields": [ + {"name": "producerIndex", "allowUnsafeAccess": true} + ] + }, + { + "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields", + "fields": [ + {"name": "producerLimit", "allowUnsafeAccess": true} + ] + }, + { + "name" : "org.neo4j.driver.internal.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields", + "fields": [ + {"name": "consumerIndex", "allowUnsafeAccess": true} + ] + } +] From 9012a837ffef0ce686badadd5df69df3b6a8cd32 Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Wed, 6 Oct 2021 16:16:54 +0200 Subject: [PATCH 2/2] Fix dev leftovers. --- driver/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/pom.xml b/driver/pom.xml index 3251f5c293..26f5adf909 100644 --- a/driver/pom.xml +++ b/driver/pom.xml @@ -93,7 +93,7 @@ - -slim + -slim