Alter buildscripts in examples so they will use globally set kotlin and lib version
Update samples to latest API
diff --git a/examples/README.md b/examples/README.md
index edaaa4a..9c3500b 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -4,7 +4,9 @@
### Example-multiplatform
-Provides setup for multiplatform library with kotlinx.serialization on JVM, JS and Native targets using new multiplatform model from Kotlin 1.3 ('kotlin-multiplatform' plugin). Also features how one can setup tests for JS.
+Provides setup for multiplatform library with kotlinx.serialization on JVM, JS and Native targets using
+new multiplatform model from Kotlin 1.3 ('kotlin-multiplatform' plugin). Also features how one can
+setup tests for JS.
### Example-jvm
@@ -27,9 +29,23 @@
### Example-visitors
Provides setup for Gradle using **Kotlin Gradle DSL** and 'kotlin.jvm' plugin.
-Showcases how one can use functionality of visiting serializable class descriptors tree to extract different metadata from the class, e.g. Json schema or .proto definition.
-It also features ability to use kotlinx.serialization library in Gradle's [composite build with dependency substitution](https://docs.gradle.org/current/userguide/composite_builds.html#included_build_declaring_substitutions).
+Showcases how one can use functionality of visiting serializable class descriptors tree to extract
+different metadata from the class, e.g. Json schema or .proto definition.
## Launching samples
You can use `./gradlew run` to run all samples or `./gradlew :folder-name:run` to run a particular sample.
+
+## Opening samples in IDEA
+
+All samples are subprojects of the `kotlinx-serialization-examples` project, located in this folder.
+Just import the `build.gradle` file into IDEA.
+
+## Grabbing samples
+
+Feel free to copy-paste any particular sample you need.
+Copy folder with sample and its `build.gradle`;
+you can also take the `gradle.properties` file from this folder, since it provides project properties
+with kotlin & serialization versions.
+For `example-multiplatform` and `example-visitors` you may also need
+`pluginManagement` block from `settings.gradle`.
diff --git a/examples/build.gradle b/examples/build.gradle
index e69de29..a9d3977 100644
--- a/examples/build.gradle
+++ b/examples/build.gradle
@@ -0,0 +1,25 @@
+subprojects {
+ buildscript {
+ repositories {
+ jcenter()
+ maven { url "https://kotlin.bintray.com/kotlin-eap" }
+ maven { url "https://kotlin.bintray.com/kotlin-dev" }
+ }
+ }
+
+
+ repositories {
+ jcenter()
+ maven { url "https://kotlin.bintray.com/kotlin-eap" }
+ maven { url "https://kotlin.bintray.com/kotlin-dev" }
+ afterEvaluate {
+ maven {
+ url "https://kotlin.bintray.com/kotlinx"
+ credentials {
+ username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
+ password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
+ }
+ }
+ }
+ }
+}
diff --git a/examples/example-js/build.gradle b/examples/example-js/build.gradle
index c429089..95d6f51 100644
--- a/examples/example-js/build.gradle
+++ b/examples/example-js/build.gradle
@@ -17,15 +17,11 @@
version '1.0-SNAPSHOT'
buildscript {
- ext.kotlin_version = '1.3.20'
- ext.serialization_version = '0.10.0'
+ // see ../gradle.properties
+ ext.kotlin_version = mainKotlinVersion
+ ext.serialization_version = mainLibVersion
ext.web_path = 'web'
- repositories {
- jcenter()
- maven { url "https://kotlin.bintray.com/kotlin-dev" }
- }
-
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
@@ -37,12 +33,7 @@
repositories {
jcenter()
- maven { url "https://kotlin.bintray.com/kotlinx"
- credentials {
- username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
- password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
- }}
- maven { url "https://kotlin.bintray.com/kotlin-dev" }
+ maven { url "https://kotlin.bintray.com/kotlinx" }
}
dependencies {
diff --git a/examples/example-js/src/main/kotlin/MyApp.kt b/examples/example-js/src/main/kotlin/MyApp.kt
index 432c9e4..712e552 100644
--- a/examples/example-js/src/main/kotlin/MyApp.kt
+++ b/examples/example-js/src/main/kotlin/MyApp.kt
@@ -10,7 +10,7 @@
data class Data(@SerialId(1) val a: Int, @SerialId(2) val b: String)
@Serializable
-data class DataList(@SerialId(1) @Optional val list: List<Data> = emptyList())
+data class DataList(@SerialId(1) val list: List<Data> = emptyList())
fun main() {
diff --git a/examples/example-jvm/build.gradle b/examples/example-jvm/build.gradle
index 34827a5..72dceb5 100644
--- a/examples/example-jvm/build.gradle
+++ b/examples/example-jvm/build.gradle
@@ -15,13 +15,9 @@
*/
buildscript {
- ext.kotlin_version = '1.3.20'
- ext.serialization_version = '0.10.0'
-
- repositories {
- jcenter()
- maven { url "https://kotlin.bintray.com/kotlin-dev" }
- }
+ // see ../gradle.properties
+ ext.kotlin_version = mainKotlinVersion
+ ext.serialization_version = mainLibVersion
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
@@ -35,12 +31,7 @@
repositories {
jcenter()
- maven { url "https://kotlin.bintray.com/kotlinx"
- credentials {
- username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
- password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
- }}
- maven { url "https://kotlin.bintray.com/kotlin-dev" }
+ maven { url "https://kotlin.bintray.com/kotlinx" }
}
sourceSets {
diff --git a/examples/example-jvm/src/WithDemo.kt b/examples/example-jvm/src/WithDemo.kt
index 7ea3c24..cd5f578 100644
--- a/examples/example-jvm/src/WithDemo.kt
+++ b/examples/example-jvm/src/WithDemo.kt
@@ -1,26 +1,10 @@
import kotlinx.serialization.*
-import kotlinx.serialization.context.*
+import kotlinx.serialization.modules.*
import kotlinx.serialization.json.Json
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*
-/*
- * Copyright 2017 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
@Serializable
data class Data(
val id: Int,
@@ -48,6 +32,6 @@
fun main(args: Array<String>) {
val o = Data(1, Payload("lorem ipsum dolor sit amet"), Date())
- val json = Json(indented = true).apply { install(SimpleModule(Date::class, DateSerializer)) }
+ val json = Json(indented = true, context = serializersModule(DateSerializer))
println(json.stringify(Data.serializer(), o))
}
diff --git a/examples/example-multiplatform/build.gradle b/examples/example-multiplatform/build.gradle
index f11d407..283a134 100644
--- a/examples/example-multiplatform/build.gradle
+++ b/examples/example-multiplatform/build.gradle
@@ -1,4 +1,6 @@
buildscript {
+ ext.serialization_version = mainLibVersion
+
repositories {
mavenCentral()
jcenter()
@@ -9,14 +11,17 @@
}
}
+// see ../settings.gradle so this plugins could be resolved
plugins {
- id 'kotlin-multiplatform' version '1.3.20'
- id 'kotlinx-serialization' version '1.3.20'
+ id 'kotlin-multiplatform'
+ id 'kotlinx-serialization'
}
+
repositories {
mavenCentral()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
+
group 'com.example'
version '0.0.1'
@@ -45,7 +50,7 @@
commonMain {
dependencies {
implementation kotlin('stdlib-common')
- implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.10.0"
+ implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
}
}
commonTest {
@@ -57,7 +62,7 @@
jvmMain {
dependencies {
implementation kotlin('stdlib-jdk8')
- implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.10.0"
+ implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
}
}
jvmTest {
@@ -69,7 +74,7 @@
jsMain {
dependencies {
implementation kotlin('stdlib-js')
- implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:0.10.0"
+ implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
}
}
jsTest {
@@ -79,7 +84,7 @@
}
macosMain {
dependencies {
- implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.10.0"
+ implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
}
}
macosTest {
diff --git a/examples/example-multiplatform/gradle.properties b/examples/example-multiplatform/gradle.properties
index 23d6ff6..117616e 100644
--- a/examples/example-multiplatform/gradle.properties
+++ b/examples/example-multiplatform/gradle.properties
@@ -6,3 +6,5 @@
mocha_version = 4.1.0
mocha_teamcity_reporter_version = 2.2.2
source_map_support_version = 0.5.3
+
+#org.jetbrains.kotlin.native.jvmArgs=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5007
diff --git a/examples/example-multiplatform/src/commonTest/kotlin/sample/JsonTest.kt b/examples/example-multiplatform/src/commonTest/kotlin/sample/JsonTest.kt
index d6e9448..4fb7562 100644
--- a/examples/example-multiplatform/src/commonTest/kotlin/sample/JsonTest.kt
+++ b/examples/example-multiplatform/src/commonTest/kotlin/sample/JsonTest.kt
@@ -23,7 +23,7 @@
class JsonTest {
private val originalData = Data("Hello", mapOf(42 to "forty-two"))
- private val originalString = """{"s":"Hello","m":{42:"forty-two"}}"""
+ private val originalString = """{"s":"Hello","m":{"42":"forty-two"}}"""
@Test
fun testStringForm() {
diff --git a/examples/example-native/build.gradle b/examples/example-native/build.gradle
index 4009cc6..249a52d 100644
--- a/examples/example-native/build.gradle
+++ b/examples/example-native/build.gradle
@@ -16,6 +16,9 @@
buildscript {
ext.serializationRepo = "https://dl.bintray.com/kotlin/kotlinx/"
+ // see ../gradle.properties
+ ext.kotlin_version = mainKotlinVersion
+ ext.serialization_version = mainLibVersion
repositories {
jcenter()
@@ -24,7 +27,7 @@
}
dependencies {
- classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:1.3.20-eap-100"
+ classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$mainKotlinVersion"
}
}
@@ -51,7 +54,7 @@
}
dependencies {
- implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.10.0"
+ implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$mainLibVersion"
}
task run(type: Exec, dependsOn: "build") {
diff --git a/examples/example-visitors/build.gradle.kts b/examples/example-visitors/build.gradle.kts
index 0a36e8a..351f7b6 100644
--- a/examples/example-visitors/build.gradle.kts
+++ b/examples/example-visitors/build.gradle.kts
@@ -1,7 +1,7 @@
plugins {
// Apply the Kotlin JVM plugin to add support for Kotlin on the JVM.
- id("org.jetbrains.kotlin.jvm") version "1.3.20"
- id("kotlinx-serialization") version "1.3.20"
+ id("org.jetbrains.kotlin.jvm") version "whatever" // ../settings.gradle overrides plugin resolution rules
+ id("kotlinx-serialization")
// Apply the application plugin to add support for building a CLI application.
application
@@ -17,7 +17,7 @@
dependencies {
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
- implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-local:0.10.0")
+ implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:${properties["mainLibVersion"]}")
// Use the Kotlin test library.
testImplementation("org.jetbrains.kotlin:kotlin-test")
diff --git a/examples/example-visitors/src/main/kotlin/App.kt b/examples/example-visitors/src/main/kotlin/App.kt
index 56b0312..04d07c6 100644
--- a/examples/example-visitors/src/main/kotlin/App.kt
+++ b/examples/example-visitors/src/main/kotlin/App.kt
@@ -20,7 +20,7 @@
import kotlinx.serialization.schema.*
@Serializable
-data class Data(val a: Int, @Optional val b: String = "42")
+data class Data(val a: Int, val b: String = "42")
fun main(args: Array<String>) {
println(">> Sample of Json schema: ")
diff --git a/examples/gradle.properties b/examples/gradle.properties
new file mode 100644
index 0000000..9bd3744
--- /dev/null
+++ b/examples/gradle.properties
@@ -0,0 +1,2 @@
+mainKotlinVersion=1.3.30-eap-125
+mainLibVersion=0.11.0-1.3.30-eap-125
diff --git a/examples/settings.gradle b/examples/settings.gradle
index 54e9cc1..ef88c79 100644
--- a/examples/settings.gradle
+++ b/examples/settings.gradle
@@ -2,10 +2,13 @@
resolutionStrategy {
eachPlugin {
if (requested.id.id == "kotlin-multiplatform") {
- useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
+ useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:$mainKotlinVersion")
+ }
+ if (requested.id.id == "org.jetbrains.kotlin.jvm") {
+ useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:$mainKotlinVersion")
}
if (requested.id.id == "kotlinx-serialization") {
- useModule("org.jetbrains.kotlin:kotlin-serialization:${requested.version}")
+ useModule("org.jetbrains.kotlin:kotlin-serialization:$mainKotlinVersion")
}
}
}
@@ -29,8 +32,14 @@
enableFeaturePreview('GRADLE_METADATA')
-includeBuild("../") {
- dependencySubstitution {
- substitute(module("org.jetbrains.kotlinx:kotlinx-serialization-runtime-local")).with(project(":jvm"))
- }
-}
+
+// Uncomment this to include build of the runtime library itself
+// https://docs.gradle.org/current/userguide/composite_builds.html#included_build_declaring_substitutions
+
+//includeBuild("../") {
+// dependencySubstitution {
+// substitute(module("org.jetbrains.kotlinx:kotlinx-serialization-runtime")).with(project(":jvm"))
+// substitute(module("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common")).with(project(":common"))
+// substitute(module("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js")).with(project(":js"))
+// }
+//}