Ray Rahke
03/13/2024, 2:04 AMsourceSets{
footest {
java {
srcDirs("src/footest")
}
}
}
...what? I can't make sense of this
so we are saying footest is a new sourceSet... which I guess we can just do for arbitrary names? and then saying that java is a sub source set? Or is it instead setting a configuration value java behavior, and so it must be a special keyword here and not something I can just invent?
this is all so implicit and requires already knowing everything to get what is going on.Ray Rahke
03/13/2024, 4:59 AMtest/
folders at arbitrary depths of subfoldering in my root. Is it possible to configure Gradle/JUnit to allow this
└── src
└── foo
├── Foo.kt
├── FooDep.kt
├── bar
│ ├── Bar.kt
│ └── test
│ └── Bartest.kt
└── test
├── FooDeptest.kt
└── Footest.kt
Ray Rahke
03/13/2024, 5:24 AMOmico
03/13/2024, 7:13 AM@Target(
AnnotationTarget.PROPERTY,
AnnotationTarget.TYPE,
AnnotationTarget.VALUE_PARAMETER,
)
annotation class StringResource
// formatX only works with @StringResource annotated strings
fun @StringResource String.formatX(vararg arguments: Any): String = format(args = arguments)
fun main() {
Strings().hello.formatX("xxx")
// The below line should be shown as an error
"Hello, %s".formatX("xxx")
}
data class Strings(
@StringResource val hello: String = "Hello, %s",
)
Ray Rahke
03/13/2024, 7:21 AMkotlinc Main.kt -include-runtime -d out.jar && java -jar out.jar
, I get unresolved errors about my package imports.Bernhard
03/13/2024, 7:48 AMDinesh Sharma
03/13/2024, 3:25 PMy
03/13/2024, 6:56 PMInt.toUInt()
, or otherwise construct a UInt
, from Java?Nikita Yatskivskiy
03/14/2024, 12:24 PMPihentagy
03/14/2024, 2:28 PMdata class MyClass @JsonCreator constructor (
var changedAt: Date,
var from: Int,
var to: Int,
var percentChanged: Int,
var levelUsed: Int,
)
Vampire
03/14/2024, 2:36 PMkotlin-dsl
plugin and contains a pre-compiled script plugin (also had this with plain-old .kt
file under same circumstances).
If I have simplified this code in the plugin:
val artifactsGetter: Provider<Configuration>.(Action<AttributeContainer>) -> Provider<ArtifactView> =
{ attributesAction -> map { it.incoming.artifactView { attributes(attributesAction) } } }
configurations
.runtimeClasspath
.artifactsGetter {
attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.JAR_TYPE)
}
It compiles perfectly fine.
But if I try to apply that plugin, I get
class Bar_gradle$$$result$1 cannot be cast to class org.gradle.api.Action (Bar_gradle$$$result$1 is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @649f4a9; org.gradle.api.Action is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @5f9d02cb)
If I look at the bytecode with javap
what is generated is
final class Bar_gradle$$$result$1 extends kotlin.jvm.internal.Lambda implements kotlin.jvm.functions.Function1<org.gradle.api.attributes.AttributeContainer, kotlin.Unit> {
Does anyone have an idea why this is happening and whose "fault" it is?
Should I report this to Kotlin or Gradle?
Is there a generic work-around besides changing every case that fails at runtime to .artifactsGetter(Action { ... })
instead of .artifactsGetter { ... }
?
(With Gradle 7.6.4 and thus KGP 1.7.10 it worked fine as long as the language version stayed at 1.4, but started to fail when I set it to 1.7, with Gradle 8.6 and thus KGP 1.9.20 it even fails with language version 1.4)Ray Rahke
03/15/2024, 8:20 AMgradle run
Starting a Gradle Daemon, 1 busy and 1 stopped Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'vscode-remote-try-kotlin'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23.
Required by:
project : > org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.9.23
> Cannot choose between the following variants of org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23:
- gradle70JavadocElements
- gradle70RuntimeElements
- gradle70SourcesElements
- gradle71JavadocElements
what is this and how to fix?Ray Rahke
03/15/2024, 9:20 AMbuild.properties.kts
file. But I've now gone the route of setting up a gradle project from scratch using the gradle init
walkthrough tool, and it generated a settings.gradle.kts
. Seems like it does the same thing as build.properties.kts
? Does the name not matter?Ray Rahke
03/15/2024, 10:29 AMplugins {
kotlin("jvm") version "1.9.23"
application
}
repositories {
mavenCentral()
}
application {
mainClass.set("MainKt")
}
sourceSets {
main {
kotlin.srcDirs("src/")
}
}
But then when I try changing jvm to multiplatform
plugins {
kotlin("multiplatform") version "1.9.23"
application
I get the following error
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file '/workspaces/testkotlin/build.gradle.kts' line: 13
* What went wrong:
Script compilation error:
Line 13: kotlin.srcDirs("src/")
^ Unresolved reference: srcDirs
Why does it differ here? it's as if the syntax for the gradle build file changes based on the plugin.Hasan Tunçay
03/15/2024, 12:21 PMRay Rahke
03/15/2024, 3:49 PMrequestAnimationFrame()
fun main() {
requestAnimationFrame(::main)
}
but receive
Unresolved reference: requestAnimationFrame
I have tried many combinations of imports, and all of them at once.
import kotlinx.browser.document
import kotlinx.browser.window
import org.w3c.dom.*
import org.w3c.dom.events.*
import kotlin.browser.window
What do I need to import to get access to this standard JS function?Ray Rahke
03/15/2024, 4:17 PMwindow.onload()
window.onload {
val canvas = document.getElementById("canvas")
}
getting error
Task :compileKotlinJs FAILED
e: Reference has a nullable type '((Event) -> dynamic)?', use explicit '?.invoke()' to make a function-like call instead
e: Type mismatch: inferred type is () -> Unit but Event was expected
What is the syntax for this?
I tried window?.invoke().onload {
and that also got an errorDarryl Miles
03/15/2024, 7:15 PMfun myMethod(): java.util.function.Function<Int,String> {
return { value: Int ->
if(value == 42) "42" else ""
} as Function<Int,String> // heh
}
Ray Rahke
03/16/2024, 9:03 AMwindow.onload()
. the documentation is either hard to find or nonexistantSlackbot
03/16/2024, 5:30 PMDarryl Miles
03/16/2024, 5:31 PMRay Rahke
03/16/2024, 6:01 PMfun test(a: Number, y: Number) {
return a / y
}
It errors
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline operator fun BigDecimal.div(other: BigDecimal): BigDecimal defined in kotlin
public inline operator fun BigInteger.div(other: BigInteger): BigInteger defined in kotlinkotlin(UNRESOLVED_REFERENCE_WRONG_RECEIVER)
I do not want to change the function signature to fun test(a: Double, y: Double)
I can do this internally to avoid changing the function signature
return a as Double / y as Double
But it is cumbersome.
Does the Number
type not have any way to do division?Ray Rahke
03/16/2024, 6:46 PMsrc/main.kt
and src/helpers/foo.kt
At the top of foo.kt
I say package helpers
, then in main.kt
I do import helpers
. I get
Packages cannot be importedkotlin(PACKAGE_CANNOT_BE_IMPORTED)
Alexander Yi
03/16/2024, 8:52 PMRay Rahke
03/17/2024, 3:09 AMThread.sleep(1000)
which seems to do nothing. Is there no simple time.sleep()
equivalent?Ray Rahke
03/17/2024, 3:28 AMall you have to do is enableWhat does "reimporting the gradle project" mean if I am not using IntelliJ? is there a command I can run on the terminal?in theorx-olive
set inorxFeatures
and reimport the gradle project.build.gradle.kts
Ray Rahke
03/17/2024, 4:57 AMBernhard
03/18/2024, 11:29 AMGamar Mustafa
03/18/2024, 1:27 PMPHondogo
03/19/2024, 9:10 AMabstract class T1 {
var x = 5
}
data class T2(
val y: Int
) : T1()
@Test
fun test() {
val a = T2(y=10)
a.x = 100
val b = a.copy(y = 99)
println(b.x) // 5 // why x is not copied?
}