Skip to content

Commit b749dd1

Browse files
authored
Provide killswitch for JPMS & improve building.md (#2105)
Add idea.active to disableJPMS check to avoid red code in IDE. Also add stdlib-jdk8 to Hocon dependencies explicitly for java.time.Duration.toKotlinDuration() (not sure why it was available without this dep though)
1 parent d1640e6 commit b749dd1

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Kotlin serialization consists of a compiler plugin, that generates visitor code
3535
* **Additional links**
3636
* [Kotlin Serialization Guide](docs/serialization-guide.md)
3737
* [Full API reference](https://kotlinlang.org/api/kotlinx.serialization/)
38+
* [Submitting issues and PRs](CONTRIBUTING.md)
39+
* [Building this library](docs/building.md)
3840

3941
## Introduction and references
4042

buildSrc/src/main/kotlin/Java9Modularity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ object Java9Modularity {
1919
@JvmStatic
2020
@JvmOverloads
2121
fun Project.configureJava9ModuleInfo(multiRelease: Boolean = true) {
22+
val disableJPMS = this.rootProject.extra.has("disableJPMS")
23+
val ideaActive = System.getProperty("idea.active") == "true"
24+
if (disableJPMS || ideaActive) return
2225
val kotlin = extensions.findByType<KotlinProjectExtension>() ?: return
2326
val jvmTargets = kotlin.targets.filter { it is KotlinJvmTarget || it is KotlinWithJavaTarget<*> }
2427
if (jvmTargets.isEmpty()) {

docs/building.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22

33
## JDK version
44

5-
To build Kotlin Serialization JDK version 9 or higher is required.
5+
To build Kotlin Serialization JDK version 11 or higher is required. Make sure this is your default JDK (`JAVA_HOME` is set accordingly).
66
This is needed to compile the `module-info` file included for JPMS support.
77

8+
In case you are determined to use different JDK version, or experience problems with JPMS you can turn off compilation of modules
9+
completely with `disableJPMS` property: add `disableJPMS=true` to gradle.properties or `-PdisableJPMS` to Gradle CLI invocation.
10+
811
## Runtime library
912

1013
Kotlin Serialization runtime library itself is a [multiplatform](http://kotlinlang.org/docs/reference/multiplatform.html) project.
11-
To build library from the source and run all tests, use `./gradlew build`. Corresponding platform tasks like `jvmTest`, `jsTest` and so on are also available.
14+
To build library from the source and run all tests, use `./gradlew build`. Corresponding platform tasks like `jvmTest`, `jsIrTest`, `nativeTest` and so on are also available.
15+
16+
Project can be opened in in Intellij IDEA without additional prerequisites.
17+
In case you want to work with Protobuf tests, you may need to run `./gradlew generateTestProto` beforehand.
18+
1219

13-
To install it into the local Maven repository, run `./gradlew publishToMavenLocal`.
20+
To install runtime library into the local Maven repository, run `./gradlew publishToMavenLocal`.
1421
After that, you can include this library in arbitrary projects like usual gradle dependency:
1522

1623
```gradle
@@ -23,17 +30,19 @@ dependencies {
2330
}
2431
```
2532

26-
To open project in Intellij IDEA, first run `./gradlew generateTestProto` from console.
27-
Make sure you've set an option 'Use Gradle wrapper' on import to use a correct version of Gradle.
28-
You may also need to mark `runtime/build/generated/source/proto/test/java` as 'Generated source root' to build project/run tests in IDE without delegating a build to Gradle.
29-
This requires Kotlin 1.3.11 and higher.
33+
Note that by default, only one Native target is built (the one that is the current host, e.g. `macosX64` on Intel Mac machines, `linuxX64` on linux machines, etc).
34+
To compile and publish all Native artifacts, not only the host one, use Gradle property `native.deploy=true`.
3035

31-
To use snapshot version of compiler (if you have built it from sources), use flag `-Pbootstrap`. To compile and publish all Native artifacts, not only the host one, use `-Pnative.deploy=true`.
36+
To use snapshot version of compiler (if you have built and install it from sources), use flag `-Pbootstrap`.
37+
If you have built both Kotlin and Kotlin/Native compilers, set `KONAN_LOCAL_DIST` environment property to the path with Kotlin/Native distribution
38+
(usually `kotlin-native/dist` folder inside Kotlin project).
3239

33-
`master` branch of library should be binary compatible with latest released compiler plugin. In case you want to test some new features from other branches, which are still in development and may not be compatible in terms of bytecode produced by plugin, you'll need to build the plugin by yourself.
40+
`master` and `dev` branches of library should be binary compatible with latest released compiler plugin. In case you want to test some new features from other branches,
41+
which are still in development and may not be compatible in terms of bytecode produced by plugin, you'll need to build the plugin by yourself.
3442

3543
## Compiler plugin
3644

3745
Compiler plugin for Gradle/Maven and IntelliJ plugin, starting from Kotlin 1.3, are embedded into the Kotlin compiler.
3846

39-
Sources and steps to build it are located [here](https://github.com/JetBrains/kotlin/blob/master/plugins/kotlin-serialization/kotlin-serialization-compiler/). In general, you'll just need to run `./gradlew dist install` to get `1.x.255` versions of Kotlin compiler, stdlib and serialization plugins in the Maven local repository.
47+
Sources and steps to build it are located [here](https://github.com/JetBrains/kotlin/tree/master/plugins/kotlinx-serialization).
48+
In short, you'll just need to run `./gradlew dist install` to get `1.x.255-SNAPSHOT` versions of Kotlin compiler, stdlib and serialization plugins in the Maven local repository.

formats/hocon/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ java {
2121
dependencies {
2222
api project(':kotlinx-serialization-core')
2323
api 'org.jetbrains.kotlin:kotlin-stdlib'
24+
api 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
2425

2526
api 'com.typesafe:config:1.4.1'
2627

0 commit comments

Comments
 (0)