Skip to content

Commit

Permalink
Create a dedicated bundle / UberJAR module. (#1029)
Browse files Browse the repository at this point in the history
* Create a dedicated bundle / UberJAR module.

This provides the driver UberJAR as it is known and used plus a slim deployment. It works by turning the previous main artifact into `neo4j-java-driver-slim` and the new bundle will be `neo4j-java-driver`.

The bundle depends on the slim artifact, extracts it and attaches it during the build so that a valid JavaDoc artifact (and sources artifact) are created and than shades the rest into it as before.

Care must be taken of the optional dependencies so that they are not included as well as the Reactive Streams API (so that it is a transitive dependency (the slim module is optional, otherwise the whole exercise would be in vain for downstream modules)).

* Replace unpack-deps with simple copy of resources.

Unpack dependencies works when executed after packaging, which is not the case when running `mvn test`.
  • Loading branch information
michael-simons authored Oct 20, 2021
1 parent fa51e5c commit d8dce60
Show file tree
Hide file tree
Showing 15 changed files with 424 additions and 199 deletions.
File renamed without changes.
4 changes: 4 additions & 0 deletions bundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Aggregator project for building the single JAR with shaded dependencies.

This module aggregates the slim version, unpacks it and repackages it.
The sources are unpacked so that an individual JavaDoc artifact is produced, too.
11 changes: 11 additions & 0 deletions bundle/osgi.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package-version=${version;===;${Bundle-Version}}

Export-Package: \
*;version="${package-version}"

Import-Package: \
!io.netty.*, \
!reactor.core.*, \
!com.oracle.svm.*, \
javax.security.cert, \
*
188 changes: 188 additions & 0 deletions bundle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver-parent</artifactId>
<version>4.4-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>neo4j-java-driver</artifactId>

<packaging>jar</packaging>
<name>Neo4j Java Driver</name>
<description>Access to the Neo4j graph database through Java</description>

<properties>
<moduleName>org.neo4j.driver</moduleName>
<rootDir>${project.basedir}/..</rootDir>
<maven.deploy.skip>false</maven.deploy.skip>
</properties>

<dependencies>
<!-- The original driver that will be repackaged. -->
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver-slim</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>

<!-- Optional and / or provided dependencies, as they are not transitive to the original driver they must be declared again. -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
</dependency>

<!-- As we pretend the driver being provided only, we need be explicit about the one dependency we actually didn't shade. -->
<dependency>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Extract the original sources again -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-appCtx</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/slim</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${rootDir}/driver/src/main/java</directory>
<includes>**\/*.java</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Attach them -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-original-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/slim</source>
</sources>
</configuration>
</execution>
<execution>
<id>set-osgi-version</id>
<phase>validate</phase>
<goals>
<goal>parse-version</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<index>true</index>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifest>
<packageName>org/neo4j/driver</packageName>
</manifest>
<manifestEntries>
<!-- This is used to programmatically determine the driver version -->
<Implementation-Version>${project.version}-${build.revision}</Implementation-Version>
<!-- Stable module name for JDK9 automatic modules -->
<Automatic-Module-Name>${moduleName}</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>io.netty:*</include>
<include>io.projectreactor:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>org.neo4j.driver.internal.shaded.io.netty</shadedPattern>
</relocation>
<relocation>
<pattern>reactor</pattern>
<shadedPattern>org.neo4j.driver.internal.shaded.reactor</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<filters>
<filter>
<artifact>io.netty:*</artifact>
<excludes>
<exclude>META-INF/native-image/**</exclude>
</excludes>
</filter>
</filters>
<shadeTestJar>true</shadeTestJar>
<createSourcesJar>true</createSourcesJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"name": "org.neo4j.driver.internal.shaded.io.netty.channel.socket.nio.NioSocketChannel",
"methods": [
{ "name": "<init>", "parameterTypes": [] }
]
},
{
"name": "org.neo4j.driver.internal.shaded.io.netty.channel.socket.nio.NioServerSocketChannel",
"methods": [
{ "name": "<init>", "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}
]
}
]
4 changes: 1 addition & 3 deletions driver/osgi.bnd
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package-version=${version;===;${Bundle-Version}}

Export-Package: \
!*.internal.*, \
*;version="${package-version}"

Import-Package: \
!io.netty.*, \
!reactor.core.*, \
!com.oracle.svm.*, \
javax.security.cert, \
*

Loading

0 comments on commit d8dce60

Please sign in to comment.