msoulatre
07/12/2023, 1:32 PMpackage.json
of my multiplatform project with compilations["main"].packageJson
.
Not sure if this should be considered a bug and if there are alternatives. More details in thread.
edit: turned out to be an issue with gradle caching/serialization so some data was not available in the packageJson closure, see thread.msoulatre
07/12/2023, 1:33 PMcompilations["main"].packageJson {
customField("name", npmArtifactName)
customField("version", npmArtifactVersion)
}
Build fails with the following error :
Failed to query the value of task ':jsPackageJson' property 'npmResolutionManager'.
> Could not isolate value org.jetbrains.kotlin.gradle.targets.js.npm.KotlinNpmResolutionManager$Parameters_Decorated@be493fd of type KotlinNpmResolutionManager.Parameters
> Could not serialize value of type Build_gradle...
Setting other custom fields that the normal build would not set still works.
It breaks in the same way using :
compilations["main"].packageJson {
name = npmArtifactName
version = npmArtifactVersion
}
Both were still working with kotlin 1.8.22.Rob Murdock
07/12/2023, 1:46 PMRob Murdock
07/12/2023, 1:46 PMRob Murdock
07/12/2023, 1:47 PMEdoardo Luppi
07/12/2023, 1:57 PMname
works here.
Setting a version
breaks kotlinNpmInstall
somehowAdam S
07/12/2023, 2:30 PMversion.toString()
msoulatre
07/12/2023, 2:42 PMcustomField("name", "newName")
customField("version", "3.0.0")
Rob Murdock
07/12/2023, 2:42 PMmsoulatre
07/12/2023, 2:46 PMval npmArtifactVersion = version
...
compilations["main"].packageJson {
customField("version", npmArtifactVersion)
}
breaks the build for meAdam S
07/12/2023, 2:49 PMpackageJson {}
block?
compilations["main"].packageJson {
val npmArtifactVersion = version
customField("version", npmArtifactVersion)
}
Adam S
07/12/2023, 2:50 PMval npmArtifactVersion = version
kotlin {
...
compilations["main"].packageJson {
val npmArtifactVersion = npmArtifactVersion
customField("version", npmArtifactVersion)
}
}
Rob Murdock
07/12/2023, 2:51 PMRob Murdock
07/12/2023, 2:55 PMmsoulatre
07/12/2023, 3:01 PMmsoulatre
07/12/2023, 3:04 PMval npmPublishId = "some-other-id"
val npmArtifactVersion = "$version-$npmPublishId"
and npmPublishId has to be defined in the closure as well, otherwise it still breaks (I don't have to access it outside so it's fine for me)Adam S
07/12/2023, 3:08 PMAdam S
07/12/2023, 3:08 PMtype Build_gradle
comes from. And the contents go into an init block.
class Build_gradle: GradleBuildScriptContext {
init {
/* .kts script contents goes here*/
}
}
Adam S
07/12/2023, 3:10 PMval npmPublishId
at the top level, you’ve got a value that basically depends on the outer Build_gradle type. And that type extends from some Gradle scripting context type, which is where all of the Gradle functions come from
class Build_gradle: GradleBuildScriptContext {
init {
val npmPublishId = "..." // inexorably linked with the Build_gradle class
}
}
Adam S
07/12/2023, 3:13 PMnpmPublishId
, and even though npmPublishId
is just a string, it depends on Build_gradle
, which extends from the Gradle scripting context, and that is far too complicated to serialize. And so you end up with lovely errors like Could not serialize value of type Build_gradle
msoulatre
07/12/2023, 3:19 PMAdam S
07/12/2023, 3:23 PMEdoardo Luppi
07/12/2023, 4:13 PMversion = "2.0"
This cannot work, the correct one is
version = "2.0.0"
So there is no conversion done internally, it has to follow semantic versioning