• 11
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

If we would like to build a multiplatform project with Kotlin and we have a structure like this one:

common
android
  android1
  android2
backend
  api1
  api2

where in the common module we have 3 targets / presets:

  • jvm (with common code to all jvm based projects)
  • jvmAndroid (with common code to all jvm android projects, depends on jvm)
  • jvmApi (with common code to all jvm api projects, depends on jvm)

How can we properly configure our build.gradles files to depend only on the correct preset / target?

For example, if we would like to use the common module as a dependency in our other projects we need to use something like:

dependencies {
  implementation project(':common')
}

But, is it possible to use only the correct part of the common module? Something like this (for android 1 and 2)?

dependencies {
  implementation project(':common:jvmAndroid')
}

Otherwise when we use implementation project(':common') this will get all jvm presets / targets but some code will only make sense or work in the correct platform (in this case android or api).

We can use a strategy called disambiguating targets to achieve this goal.

https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#disambiguating-targets

We need to do something like:

val commonAttribute = Attribute.of("com.example", String::class.java)

jvm {
    attributes.attribute(commonAttribute, "nameOfYourTarget")
}

Both in the "client" and "server" side. In the same way.

  • 1
Reply Report