Skip to content

Commit

Permalink
Add Gradle task to build a thin jar for Android/Kotlin project (#45)
Browse files Browse the repository at this point in the history
## What does this PR do ?

Deliver a thin jar for Android Kotlin projects.
Change Getting Started Kotlin
Add Bintray publication for the thin jar

### Other Change

Bump `ktor` version from 1.3.2 to 1.5.2

### Boyscout

Fix Server Controller documentation
  • Loading branch information
Yoann-Abbes authored Mar 11, 2021
1 parent 1f6d152 commit 580980d
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .ci/doc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./java-protect/libs/*.jar
./kotlin-protect/libs/*.jar
9 changes: 8 additions & 1 deletion .ci/doc/java-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ sourceCompatibility = 1.8

repositories {
mavenCentral()
jcenter()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'io.ktor:ktor-client-websockets:1.5.2'
compile 'io.ktor:ktor-client-okhttp:1.5.2'
compile 'io.ktor:ktor-client-cio:1.5.2'
compile 'io.ktor:ktor-client-json:1.5.2'
compile 'io.ktor:ktor-client-gson:1.5.2'
compile 'io.ktor:ktor-client-serialization:1.5.2'
compile 'com.google.code.gson:gson:2.8.5'
compile fileTree(dir: 'libs', include: ['*.jar'])
}

jar {
Expand Down
9 changes: 8 additions & 1 deletion .ci/doc/kotlin-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ sourceCompatibility = 1.8

repositories {
mavenCentral()
jcenter()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'io.ktor:ktor-client-websockets:1.5.2'
compile 'io.ktor:ktor-client-okhttp:1.5.2'
compile 'io.ktor:ktor-client-cio:1.5.2'
compile 'io.ktor:ktor-client-json:1.5.2'
compile 'io.ktor:ktor-client-gson:1.5.2'
compile 'io.ktor:ktor-client-serialization:1.5.2'
compile 'com.google.code.gson:gson:2.8.5'
compile fileTree(dir: 'libs', include: ['*.jar'])
}

jar {
Expand Down
4 changes: 2 additions & 2 deletions .ci/doc/test-snippet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

if [ ${1: -3} == ".kt" ]
then
cp /mnt/build/libs/sdk-jvm-[0-9+].[0-9+].[0-9+].jar /mnt/.ci/doc/kotlin-project/libs/ && cp $1 /mnt/.ci/doc/kotlin-project/src/main/java/SnippetTest.kt && cd /mnt/.ci/doc/kotlin-project/ && ./gradlew build && java -classpath 'libs/sdk-jvm-1.0.0.jar:' -jar build/libs/project-1.jar
cp /mnt/build/libs/sdk-jvm-[0-9+].[0-9+].[0-9+]-without-dependencies.jar /mnt/.ci/doc/kotlin-project/libs/ && cp $1 /mnt/.ci/doc/kotlin-project/src/main/java/SnippetTest.kt && cd /mnt/.ci/doc/kotlin-project/ && ./gradlew build && java -classpath 'libs/sdk-jvm-1.1.0-without-dependencies.jar:' -jar build/libs/project-1.jar
else
cp /mnt/build/libs/sdk-jvm-[0-9+].[0-9+].[0-9+].jar /mnt/.ci/doc/java-project/libs/ && cp $1 /mnt/.ci/doc/java-project/src/main/java/SnippetTest.java && cd /mnt/.ci/doc/java-project/ && ./gradlew build && java -classpath 'libs/sdk-jvm-1.0.0.jar:' -jar build/libs/project-1.jar
cp /mnt/build/libs/sdk-jvm-[0-9+].[0-9+].[0-9+]-without-dependencies.jar /mnt/.ci/doc/java-project/libs/ && cp $1 /mnt/.ci/doc/java-project/src/main/java/SnippetTest.java && cd /mnt/.ci/doc/java-project/ && ./gradlew build && java -classpath 'libs/jvm-1.1.0-without-dependencies.jar:' -jar build/libs/project-1.jar
fi
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ https://bintray.com/kuzzle/maven
<dependency>
<groupId>io.kuzzle</groupId>
<artifactId>sdk-jvm</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<type>pom</type>
</dependency>
```
Expand All @@ -54,19 +54,48 @@ https://bintray.com/kuzzle/maven
### Gradle

```groovy
compile 'io.kuzzle:sdk-jvm:1.0.0'
compile 'io.kuzzle:sdk-jvm:1.1.0'
```

For amd64:

```groovy
compile 'io.kuzzle:sdk-jvm:1.0.0'
compile 'io.kuzzle:sdk-jvm:1.1.0'
```

### Ivy

```html
<dependency org='io.kuzzle' name='sdk-jvm' rev='1.0.0'>
<dependency org='io.kuzzle' name='sdk-jvm' rev='1.1.0'>
<artifact name='sdk-jvm' ext='pom' ></artifact>
</dependency>
```

This SDK has 2 jar files that you can use:
* `sdk-jvm-<version>.jar`: this is the fat jar version, containing the SDK and all its dependencies.
* `sdk-jvm-<version>-without-dependencies.jar`: this is the thin jar version of the SDK, without any dependencies included in it.

Depending on your project, you might need one or the other version of the SDK: if you already use some of the dependencies needed by the SDK, then you need to use the thin jar version. Otherwise, you may use the fat jar one.

⚠️ Warning
If you are using the fat jar, you might have duplicate dependencies issues in a Kotlin Android Studio project. Add the following lines to your `build.gradle` file:

```groovy
configurations {
cleanedAnnotations
compile.exclude group: 'org.jetbrains'
compile.exclude group: 'org.jetbrains.kotlin'
}
```

If you are using the thin jar, make sure to add the following dependencies:

```groovy
implementation("io.ktor:ktor-client-websockets:1.5.2")
implementation("io.ktor:ktor-client-okhttp:1.5.2")
implementation("io.ktor:ktor-client-cio:1.5.2")
implementation("io.ktor:ktor-client-json:1.5.2")
implementation("io.ktor:ktor-client-gson:1.5.2")
implementation("io.ktor:ktor-client-serialization:1.5.2")
implementation("com.google.code.gson:gson:2.8.5")
```
61 changes: 48 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,36 @@ val pomDeveloperName = "kuzzle"

publishing {
publications {
create<MavenPublication>("kuzzle-sdk-jvm") {
create<MavenPublication>("kuzzle-sdk-jvm-fat") {
groupId = artifactGroup
artifactId = artifactName
version = artifactVersion
version = "${artifactVersion}-with-dependencies"
from(components["java"])

pom.withXml {
asNode().apply {
appendNode("description", pomDesc)
appendNode("name", rootProject.name)
appendNode("url", pomUrl)
appendNode("licenses").appendNode("license").apply {
appendNode("name", pomLicenseName)
appendNode("url", pomLicenseUrl)
appendNode("distribution", pomLicenseDist)
}
appendNode("developers").appendNode("developer").apply {
appendNode("id", pomDeveloperId)
appendNode("name", pomDeveloperName)
}
appendNode("scm").apply {
appendNode("url", pomScmUrl)
}
}
}
}
create<MavenPublication>("kuzzle-sdk-jvm-thin") {
groupId = artifactGroup
artifactId = artifactName
version = "${artifactVersion}-without-dependencies"
from(components["java"])

pom.withXml {
Expand Down Expand Up @@ -70,7 +96,7 @@ bintray {
key = System.getenv("BINTRAY_KEY")
publish = true

setPublications("kuzzle-sdk-jvm")
setPublications("kuzzle-sdk-jvm-fat", "kuzzle-sdk-jvm-thin")

pkg.apply {
repo = "maven"
Expand All @@ -95,7 +121,7 @@ bintray {

group = "io.kuzzle.sdk"
version = "1.1.0"
val ktorVersion = "1.3.2"
val ktorVersion = "1.5.2"

repositories {
jcenter()
Expand All @@ -113,11 +139,11 @@ dependencies {

testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
testImplementation("io.mockk:mockk:1.8.13")
testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
testImplementation("io.ktor:ktor-client-mock:1.3.2")
testImplementation("io.ktor:ktor-client-mock-jvm:$ktorVersion")
testImplementation("io.ktor:ktor-client-json-jvm:$ktorVersion")
testImplementation("io.ktor:ktor-client-mock-js:$ktorVersion")
testImplementation("io.ktor:ktor-client-mock-native:$ktorVersion")
testImplementation("io.ktor:ktor-client-mock-js:1.3.2")
testImplementation("io.ktor:ktor-client-mock-native:1.3.2")

}

Expand Down Expand Up @@ -149,12 +175,21 @@ application {
}

tasks.withType<Jar> {
archiveClassifier.set("without-dependencies")
}

tasks {
register("fatJar", Jar::class.java) {
archiveClassifier.set("")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes(
mapOf(
"Main-Class" to application.mainClassName
)
)
attributes("Main-Class" to application.mainClassName)
}
from(configurations.compileClasspath.get().map { if (it.isDirectory()) it else zipTree(it) })
from(configurations.runtimeClasspath.get()
.onEach { println("Add from dependencies: ${it.name}") }
.map { if (it.isDirectory) it else zipTree(it) })
val sourcesMain = sourceSets.main.get()
sourcesMain.allSource.forEach { println("Add from sources: ${it.name}") }
from(sourcesMain.output)
}
}
5 changes: 4 additions & 1 deletion doc/1/controllers/server/admin-exists/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ A boolean indicating whether an admin user exists or not.

<<< ./snippets/admin-exists-java.java

:::: tabs
:::
::: tab Kotlin

```kotlin
Expand All @@ -38,3 +38,6 @@ A boolean indicating whether an admin user exists or not.
## Usage

<<< ./snippets/admin-exists-kotlin.kt

:::
::::
6 changes: 5 additions & 1 deletion doc/1/controllers/server/get-all-stats/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Returns a `Map<String, Object>` containing all stored internal statistic snapsho

<<< ./snippets/get-all-stats-java.java

:::
::: tab Kotlin

```kotlin
Expand All @@ -44,4 +45,7 @@ Returns a `Map<String, Any?>` containing all stored internal statistic snapshots

## Usage

<<< ./snippets/get-all-stats-kotlin.kt
<<< ./snippets/get-all-stats-kotlin.kt

:::
::::
4 changes: 4 additions & 0 deletions doc/1/controllers/server/get-config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Returns a `Map<String, Object>` containing server configuration.

<<< ./snippets/get-config-java.java

:::
::: tab Kotlin

```kotlin
Expand All @@ -41,3 +42,6 @@ Returns a `Map<String, Any?>` containing server configuration.
## Usage

<<< ./snippets/get-config-kotlin.kt

:::
::::
6 changes: 5 additions & 1 deletion doc/1/controllers/server/get-last-stats/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Returns an `Map<String, Object>` containing the most recent statistics snapshot.

<<< ./snippets/get-last-stats-java.java

:::
::: tab Kotlin

```kotlin
Expand All @@ -45,4 +46,7 @@ Returns an `Map<String, Any?>` containing the most recent statistics snapshot.

## Usage

<<< ./snippets/get-last-stats-kotlin.kt
<<< ./snippets/get-last-stats-kotlin.kt

:::
::::
6 changes: 5 additions & 1 deletion doc/1/controllers/server/get-stats/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Returns a `Map<String, Object>` containing statistics snapshots within the provi

<<< ./snippets/get-stats-java.java

:::
::: tab Kotlin

```kotlin
Expand All @@ -59,4 +60,7 @@ Returns a `Map<String, Any?>` containing statistics snapshots within the provide

## Usage

<<< ./snippets/get-stats-kotlin.kt
<<< ./snippets/get-stats-kotlin.kt

:::
::::
4 changes: 4 additions & 0 deletions doc/1/controllers/server/info/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Returns a `Map<String, dynamic>` containing server information.

<<< ./snippets/info-java.java

:::
::: tab Kotlin

```kotlin
Expand All @@ -37,3 +38,6 @@ Returns a `Map<String, Object>` containing server information.
## Usage

<<< ./snippets/info-kotlin.kt

:::
::::
6 changes: 5 additions & 1 deletion doc/1/controllers/server/now/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Returns a `Date` representing the current server timestamp.

<<< ./snippets/now-java.java

:::
::: tab Kotlin

```kotlin
Expand All @@ -36,4 +37,7 @@ Returns a `Date` representing the current server timestamp.

## Usage

<<< ./snippets/now-kotlin.kt
<<< ./snippets/now-kotlin.kt

:::
::::
18 changes: 18 additions & 0 deletions doc/1/getting-started/java/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ Having trouble? Get in touch with us on [Discord](http://join.discord.kuzzle.io)

You can find the SDK JARs directly on [bintray](https://bintray.com/kuzzle/maven/sdk-jvm). Download and add them to your classpath.

This SDK has 2 jar files that you can use:
* `sdk-jvm-<version>.jar`: this is the fat jar version, containing the SDK and all its dependencies.
* `sdk-jvm-<version>-without-dependencies.jar`: this is the thin jar version of the SDK, without any dependencies included in it.

Depending on your project, you might need one or the other version of the SDK: if you already use some of the dependencies needed by the SDK, then you need to use the thin jar version. Otherwise, you may use the fat jar one.

If you are using the thin jar, make sure to add the following dependencies:

```groovy
implementation("io.ktor:ktor-client-websockets:1.5.2")
implementation("io.ktor:ktor-client-okhttp:1.5.2")
implementation("io.ktor:ktor-client-cio:1.5.2")
implementation("io.ktor:ktor-client-json:1.5.2")
implementation("io.ktor:ktor-client-gson:1.5.2")
implementation("io.ktor:ktor-client-serialization:1.5.2")
implementation("com.google.code.gson:gson:2.8.5")
```

::: info
The following examples are made to be executed without any IDE.
If you're using Eclipse, IntelliJ or another Java IDE, you need to add the SDK as a project dependency in your classpath.
Expand Down
Loading

0 comments on commit 580980d

Please sign in to comment.