@@ -72,7 +72,7 @@ ext.versions = [
7272 " gson" : " 2.7" ,
7373 " guava" : " 30.1-jre" ,
7474 " jackson" : " 2.11.2" ,
75- " launchdarklyJavaSdkCommon" : " 1.1.1 " ,
75+ " launchdarklyJavaSdkCommon" : " 1.2.0 " ,
7676 " okhttp" : " 4.8.1" , // specify this for the SDK build instead of relying on the transitive dependency from okhttp-eventsource
7777 " okhttpEventsource" : " 2.3.1" ,
7878 " slf4j" : " 1.7.21" ,
@@ -83,6 +83,16 @@ ext.versions = [
8383// Add dependencies to "libraries.internal" that are not exposed in our public API. These
8484// will be completely omitted from the "thin" jar, and will be embedded with shaded names
8585// in the other two SDK jars.
86+ //
87+ // Note that Gson is included here but Jackson is not, even though there is some Jackson
88+ // helper code in java-sdk-common. The reason is that the SDK always needs to use Gson for
89+ // its own usual business, so (except in the "thin" jar) we will be embedding a shaded
90+ // copy of Gson; but we do not use Jackson normally, we just provide those helpers for use
91+ // by applications that are already using Jackson. So we do not want to embed it and we do
92+ // not want it to show up as a dependency at all in our pom (and it's been excluded from
93+ // the launchdarkly-java-sdk-common pom for the same reason). However, we do include
94+ // Jackson in "libraries.optional" because we need to generate OSGi optional import
95+ // headers for it.
8696libraries. internal = [
8797 " com.launchdarkly:launchdarkly-java-sdk-common:${ versions.launchdarklyJavaSdkCommon} " ,
8898 " commons-codec:commons-codec:${ versions.commonsCodec} " ,
@@ -96,7 +106,15 @@ libraries.internal = [
96106// Add dependencies to "libraries.external" that are exposed in our public API, or that have
97107// global state that must be shared between the SDK and the caller.
98108libraries. external = [
99- " org.slf4j:slf4j-api:${ versions.slf4j} " ,
109+ " org.slf4j:slf4j-api:${ versions.slf4j} "
110+ ]
111+
112+ // Add dependencies to "libraries.optional" that are not exposed in our public API and are
113+ // *not* embedded in the SDK jar. These are for optional things that will only work if
114+ // they are already in the application classpath; we do not want show them as a dependency
115+ // because that would cause them to be pulled in automatically in all builds. The reason
116+ // we need to even mention them here at all is for the sake of OSGi optional import headers.
117+ libraries. optional = [
100118 " com.fasterxml.jackson.core:jackson-core:${ versions.jackson} " ,
101119 " com.fasterxml.jackson.core:jackson-databind:${ versions.jackson} "
102120]
@@ -114,24 +132,29 @@ libraries.test = [
114132 " com.fasterxml.jackson.core:jackson-databind:${ versions.jackson} "
115133]
116134
135+ configurations {
136+ // We need to define "internal" as a custom configuration that contains the same things as
137+ // "implementation", because "implementation" has special behavior in Gradle that prevents us
138+ // from referencing it the way we do in shadeDependencies().
139+ internal. extendsFrom implementation
140+ optional
141+ imports
142+ }
143+
117144dependencies {
118145 implementation libraries. internal
119146 api libraries. external
120147 testImplementation libraries. test, libraries. internal, libraries. external
148+ optional libraries. optional
121149
122150 commonClasses " com.launchdarkly:launchdarkly-java-sdk-common:${ versions.launchdarklyJavaSdkCommon} "
123151 commonDoc " com.launchdarkly:launchdarkly-java-sdk-common:${ versions.launchdarklyJavaSdkCommon} :sources"
124152
125153 // Unlike what the name might suggest, the "shadow" configuration specifies dependencies that
126154 // should *not* be shaded by the Shadow plugin when we build our shaded jars.
127- shadow libraries. external
128- }
155+ shadow libraries. external, libraries. optional
129156
130- configurations {
131- // We need to define "internal" as a custom configuration that contains the same things as
132- // "implementation", because "implementation" has special behavior in Gradle that prevents us
133- // from referencing it the way we do in shadeDependencies().
134- internal. extendsFrom implementation
157+ imports libraries. external
135158}
136159
137160checkstyle {
@@ -171,7 +194,6 @@ shadowJar {
171194
172195 dependencies {
173196 exclude(dependency(' org.slf4j:.*:.*' ))
174- exclude(dependency(' com.fasterxml.jackson.core:.*:.*' ))
175197 }
176198
177199 // Kotlin metadata for shaded classes should not be included - it confuses IDEs
@@ -185,7 +207,7 @@ shadowJar {
185207 shadeDependencies(project. tasks. shadowJar)
186208 // Note that "configurations.shadow" is the same as "libraries.external", except it contains
187209 // objects with detailed information about the resolved dependencies.
188- addOsgiManifest(project. tasks. shadowJar, [ project. configurations. shadow ], [])
210+ addOsgiManifest(project. tasks. shadowJar, [ project. configurations. imports ], [])
189211 }
190212
191213 doLast {
@@ -208,17 +230,17 @@ task shadowJarAll(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJ
208230 exclude ' **/*.kotlin_builtins'
209231
210232 dependencies {
211- exclude(dependency( ' com.fasterxml.jackson.core:.*:.* ' ))
233+ // Currently we don't need to exclude anything - SLF4J will be embedded, unshaded
212234 }
213235
214236 // doFirst causes the following steps to be run during Gradle's execution phase rather than the
215237 // configuration phase; this is necessary because they access the build products
216238 doFirst {
217239 shadeDependencies(project. tasks. shadowJarAll)
218- // The "all" jar exposes its bundled Gson and SLF4j dependencies as exports - but, like the
219- // default jar, it *also* imports them ("self-wiring"), which allows the bundle to use a
240+ // The "all" jar exposes its bundled SLF4j dependency as an export - but, like the
241+ // default jar, it *also* imports it ("self-wiring"), which allows the bundle to use a
220242 // higher version if one is provided by another bundle.
221- addOsgiManifest(project. tasks. shadowJarAll, [ project. configurations. shadow ], [ project. configurations. shadow ])
243+ addOsgiManifest(project. tasks. shadowJarAll, [ project. configurations. imports ], [ project. configurations. imports ])
222244 }
223245
224246 doLast {
@@ -370,14 +392,18 @@ def addOsgiManifest(jarTask, List<Configuration> importConfigs, List<Configurati
370392 // Since we're not currently able to use bnd or the Gradle OSGi plugin, we're not discovering
371393 // imports by looking at the actual code; instead, we're just importing whatever packages each
372394 // dependency is exporting (if it has an OSGi manifest) or every package in the dependency (if
373- // it doesn't). We also always add *optional* imports for Gson, so that GsonTypeAdapters will
374- // work *if* Gson is present externally.
395+ // it doesn't).
375396 def imports = forEachArtifactAndVisiblePackage(importConfigs, { a , p ->
376397 bundleImport(p, a. moduleVersion. id. version, nextMajorVersion(a. moduleVersion. id. version))
377398 }) + systemPackageImports
378- imports + = " com.google.gson;resolution:=optional"
379- imports + = " com.google.gson.reflect;resolution:=optional"
380- imports + = " com.google.gson.stream;resolution:=optional"
399+
400+ // We also always add *optional* imports for Gson and Jackson, so that GsonTypeAdapters and
401+ // JacksonTypeAdapters will work *if* Gson or Jackson is present externally. Currently we
402+ // are hard-coding the Gson packages but there is probably a better way.
403+ def optImports = [ " com.google.gson" , " com.google.gson.reflect" , " com.google.gson.stream" ]
404+ forEachArtifactAndVisiblePackage([ configurations. optional ]) { a , p -> optImports + = p }
405+ imports + = (optImports. join(" ;" ) + " ;resolution:=optional" )
406+
381407 attributes(" Import-Package" : imports. join(" ," ))
382408
383409 // Similarly, we're adding package exports for every package in whatever libraries we're
@@ -391,9 +417,7 @@ def addOsgiManifest(jarTask, List<Configuration> importConfigs, List<Configurati
391417}
392418
393419def bundleImport (packageName , importVersion , versionLimit ) {
394- def optional = packageName. startsWith(" com.fasterxml.jackson" )
395- packageName + " ;version=\" [" + importVersion + " ," + versionLimit + " )\" " +
396- (optional ? " ;resolution:=optional" : " " )
420+ packageName + " ;version=\" [" + importVersion + " ," + versionLimit + " )\" "
397421}
398422
399423def bundleExport (packageName , exportVersion ) {
0 commit comments