Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gradle task to build a thin jar for Android/Kotlin project #45

Merged
merged 14 commits into from
Mar 11, 2021
Merged
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.0.0.jar:' -jar build/libs/project-1.jar
Yoann-Abbes marked this conversation as resolved.
Show resolved Hide resolved
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/sdk-jvm-1.0.0.jar:' -jar build/libs/project-1.jar
Yoann-Abbes marked this conversation as resolved.
Show resolved Hide resolved
fi
35 changes: 30 additions & 5 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,44 @@ 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>
```
```

::: warning
Yoann-Abbes marked this conversation as resolved.
Show resolved Hide resolved
If you are using the `sdk-jvm-X.Y.Z.jar` in a Kotlin Android Studio project, consider adding the following lines to your `gradle.build` file:
Yoann-Abbes marked this conversation as resolved.
Show resolved Hide resolved

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

If have duplicate dependencies issues when you build your project, remove the lines above if you added them, and consider using the `sdk-jvm-X.Y.Z-without-dependencies.jar`. Then, you have 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,12 +36,38 @@ val pomDeveloperName = "kuzzle"

publishing {
publications {
create<MavenPublication>("kuzzle-sdk-jvm") {
create<MavenPublication>("kuzzle-sdk-jvm-fat") {
groupId = artifactGroup
artifactId = artifactName
version = artifactVersion
Yoann-Abbes marked this conversation as resolved.
Show resolved Hide resolved
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 {
asNode().apply {
appendNode("description", pomDesc)
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

:::
::::
Loading