sdeleuze
06/24/2019, 8:07 AMkotlin {
target {
browser()
sourceSets {
main {
dependencies {
implementation(kotlin("stdlib-js"))
implementation(project(":shared"))
}
}
}
}
}
Why not:
kotlin {
target {
browser()
}
}
dependencies {
implementation(kotlin("stdlib-js"))
implementation(project(":shared"))
}
For the common module, we have this pretty confusing build:
kotlin {
jvm()
js {
browser()
nodejs()
}
sourceSets {
commonMain {
dependencies {
implementation(kotlin("stdlib-common"))
}
}
commonTest {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
getByName("jvmMain").apply {
dependencies {
implementation(kotlin("stdlib-jdk8"))
}
}
getByName("jvmTest").apply {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
}
}
getByName("jsMain").apply {
dependencies {
implementation(kotlin("stdlib-js"))
}
}
getByName("jsTest").apply {
dependencies {
implementation(kotlin("test-js"))
}
}
}
}
Is it the expected final format we are going to use? cc @gaetansnrostov
06/24/2019, 8:09 AMFor the JS moduleBoth ways supported, but there is no DSL for NPM dependencies in root
dependency
section. And it is not clear how to implement it, especially for build.gradle.kts.ribesg
06/24/2019, 8:11 AMsnrostov
06/24/2019, 8:11 AMFor the common module, we have this pretty confusing buildCould you please explain what exactly is confusing?
sdeleuze
06/24/2019, 8:20 AMkotlin {
target {
browser()
}
}
dependencies {
implementation(kotlin("stdlib-js"))
implementation(project(":shared"))
implementation(npm("html-minifier:4.0.0"))
}
ribesg
06/24/2019, 8:22 AMsnrostov
06/24/2019, 8:23 AMribesg
06/24/2019, 8:24 AMsnrostov
06/24/2019, 8:24 AMorg.jetbraibs.kotlin.js
plugin applied.sdeleuze
06/24/2019, 8:24 AMribesg
06/24/2019, 8:25 AMsnrostov
06/24/2019, 8:26 AMorg.jetbraibs.kotlin.js
plugin. You can do it with org.jetbraibs.kotlin.multiplatform
only.sdeleuze
06/24/2019, 8:27 AMkotlin {
common {
dependencies {
implementation(kotlin("stdlib-common"))
testImplementation(kotlin("test-common"))
testImplementation(kotlin("test-annotations-common"))
}
}
jvm {
dependencies {
implementation(kotlin("stdlib-jdk8"))
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit"))
}
}
js {
browser()
nodejs()
dependencies {
implementation(kotlin("stdlib-js"))
testImplementation(kotlin("test-js"))
}
}
}
ribesg
06/24/2019, 8:43 AMsdeleuze
06/24/2019, 8:44 AMribesg
06/24/2019, 8:44 AMsdeleuze
06/24/2019, 8:45 AMribesg
06/24/2019, 8:46 AMsdeleuze
06/24/2019, 8:47 AMribesg
06/24/2019, 8:47 AMsdeleuze
06/24/2019, 8:50 AMgildor
06/24/2019, 8:50 AMimplementationNpm
configuration?ribesg
06/24/2019, 8:50 AMgildor
06/24/2019, 8:50 AMsdeleuze
06/24/2019, 8:52 AMgildor
06/24/2019, 8:53 AMkotlin.sourceSets.commonMain.dependencies.api("something")
use:
dependencies.commonMainApi(project("something"))
sdeleuze
06/24/2019, 8:54 AMgildor
06/24/2019, 8:57 AMsdeleuze
06/24/2019, 8:57 AMgildor
06/24/2019, 8:58 AMsdeleuze
06/24/2019, 8:59 AMimplementation(npm("html-minifier:4.0.0"))
should be replaced by npmImplementation("html-minifier:4.0.0")
?gildor
06/24/2019, 9:01 AMsdeleuze
06/24/2019, 9:01 AMgildor
06/24/2019, 9:01 AMsdeleuze
06/24/2019, 9:01 AMgildor
06/24/2019, 9:01 AMkotlin
function is just emit standard dependency id, so not really the same as npmsdeleuze
06/24/2019, 9:01 AMgildor
06/24/2019, 9:01 AMproject
is different kind of dependency, that may be harder to implementreplaced byOr, alternatevely:npmImplementation("html-minifier:4.0.0")
implementation("npm:html-minifier:4.0.0")
group
, only name of dependency and version, so in theory it’s possible to support this syntax for all dependencies, but problem that npm
is also valid maven group idsdeleuze
06/24/2019, 9:09 AMgildor
06/24/2019, 9:09 AMsdeleuze
06/24/2019, 9:09 AMgildor
06/24/2019, 9:13 AMThanks for the hint!@sdeleuze Just to make it clear, in my example I use Kotlin DSL and have static accessors for all configurations, but only because I extract config to buildSrc plugin, so it allows Gradle to generate static accessors for me, if you just declare MPP config in the same file, you have to use dynamic syntax for configurations (except of default ones, like commonMainApi etc, because they are registered by defult by MPP plugin):
jvmMainApi("something")
becomes "jvmMainApi"("something")
without static accessors, but IMO it’s still better, and if you want to declare some common configuration, just use buildSrc, so it will make all the configs type safesdeleuze
06/24/2019, 9:16 AMkotlin-dsl
plugin maybe? https://github.com/mipt-npm/kmath/blob/5be55560cffe6815ef41ef71faf36d539ef07530/buildSrc/build.gradle.ktsgildor
06/24/2019, 9:21 AMsdeleuze
06/24/2019, 9:21 AMsdeleuze
06/24/2019, 9:22 AM"jvmMainApi"("something")
gildor
06/24/2019, 9:24 AMDiscoverability is key and we can’t expect people usingI agree
sdeleuze
06/24/2019, 9:24 AMgildor
06/24/2019, 9:24 AMsnrostov
06/24/2019, 9:25 AMDiscoverability is key and we can’t expect people usingJust an idea about build.gradle.kts: what do you think about"jvmMainApi"("something")
jvm.main.api("something")
?gildor
06/24/2019, 9:26 AMjvm
in this case? Gradle Convention for dependencies block?snrostov
06/24/2019, 9:26 AMgildor
06/24/2019, 9:27 AMjvm
here is just default name of jvm
configuration, so if you define it like:
jvm("java12") { // some MPP plugin }
Dependency should have configuration like java12MainApi
reference to kotlin target created from presetShouldn’t it be
kotlin.jvm.main.api("something")
than?snrostov
06/24/2019, 9:28 AMjvm("java12") { // some MPP plugin }
maybe we can replace it with
val java12 by jvm { }
gildor
06/24/2019, 9:28 AMsdeleuze
06/24/2019, 9:38 AMConfiguration with name 'jvmMainImplementation' not found
error, what did I miss?
plugins {
kotlin("multiplatform")
}
repositories {
mavenCentral()
}
dependencies {
commonMainImplementation(kotlin("stdlib-common"))
commonTestImplementation(kotlin("test-common"))
commonTestImplementation(kotlin("test-annotations-common"))
"jvmMainImplementation"(kotlin("stdlib-jdk8"))
"jvmTestImplementation"(kotlin("test"))
"jvmTestImplementation"(kotlin("test-junit"))
"jsMainImplementation"(kotlin("stdlib-js"))
"jsTestImplementation"(kotlin("test-js"))
}
kotlin {
jvm()
js {
browser()
nodejs()
}
}
snrostov
06/24/2019, 9:39 AMgildor
06/24/2019, 9:52 AMdependencies
and kotlin
blockssdeleuze
06/24/2019, 12:37 PMDico
06/24/2019, 1:01 PM"browserMainImplementation"("dependencyNotation")
gaetan
06/28/2019, 7:12 AMsnrostov
06/28/2019, 7:24 AMproject(":core")
in commonMainApi
configuration. It is enough to specify a single project('...')
dependency in a source set’s dependencies, and the compilations that include the source set will receive a corresponding platform-specific artifact of that project. This is main reason for new mpp project layout: now platform-specific artifact selected automatically.
https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#adding-dependenciesgaetan
06/28/2019, 7:32 AMsnrostov
06/28/2019, 7:36 AMkotlin {
/* ... */
// Configure the attributes of the 'jvm6' target:
jvm("jvm6").attributes { /* ... */ }
}
Corresponding dependency artifact will be selected by matching consumer and dependency attributes. More info about this Gradle feature can be found here: https://docs.gradle.org/current/userguide/dependency_management_attribute_based_matching.html"jvm6MainApi"("com.example:foo-jvm6:1.0")
gaetan
06/28/2019, 8:07 AM