Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with Kotlin Multiplatform plugin #129

Open
JotBePunkt opened this issue Jul 16, 2019 · 10 comments
Open

Incompatible with Kotlin Multiplatform plugin #129

JotBePunkt opened this issue Jul 16, 2019 · 10 comments

Comments

@JotBePunkt
Copy link

Hi,

i wanted to use the plugin to build an image of a project I built with the Kotlin Multiplatform project (in fact I wanted to compare GraalVM and Kotlin Native). The Kotlin Plugin does not create a <projectName>-<version>.jar but a <projectName>-<version>-jvm.jar

For this case it would be create to configure the Jar file to be use (or its classifier (in this case  jvm))

@JotBePunkt
Copy link
Author

JotBePunkt commented Jul 17, 2019

I found a way to configure the task that produces the JAR file used for the graalVM native image or shared lib. There are some things that make it complicated:

  • The extension object is configured only after the apply() method of the plugin had beed called. Consequence: The task needs to be configured with the default jar task as its dependency and later replaced when the user configured something else.
  • The Kotlin Multiplatform Gradle plugin adds its tasks only when its extension is configured. Consequence: If the task that is creating the jar file is not registered yet, the nativeImage Task and sharedLibrary task needs to be registered when thee dependency task was registered. For better error handling a dummy task should be registered in the beginning (that just throws an error if the confugured task was not configured until then)

Additionally I would remove the hard dependecy to the Java plugin, so there are only thise tasks that the user wants to be configured.

@StevenACoffman
Copy link

@JotBePunkt Is it possible to share your working build.gradle(.kts) ? I'm struggling with the same pain points.

@JotBePunkt
Copy link
Author

I did not make it work yet, as described I would need to refactor the plugin. I did not get a reaction from one of the contributors, I dont know if this is welcome or not.

@yschimke
Copy link

Just hit this

  - In plugin 'com.palantir.graal' type 'com.palantir.gradle.graal.NativeImageTask' property 'jarFiles' specifies file '/Users/yschimke/IdeaProjects/emulator-tools/build/libs/emulator-tools-kmp-f632f62-dirty.jar' which doesn't exist.

* Try:
> Run with --stacktrace option to get the stack trace.

File is ./build/libs/emulator-tools-jvm-kmp-f632f62-dirty.jar

@yschimke
Copy link

Seems like a bug in the Jar task -
println(project.tasks.getByName("jar").outputs.files.singleFile) -> emulator-tools-kmp-f632f62-dirty.jar

@yschimke
Copy link

yschimke commented Jan 1, 2022

I think the assumption of jar task is the issue

println(project.tasks.getByName("jar").outputs.files.singleFile) -> certifikit-cli-0.3.0-SNAPSHOT.jar
println(project.tasks.getByName("jvmJar").outputs.files.singleFile) -> certifikit-cli-jvm-0.3.0-SNAPSHOT.jar

@yschimke
Copy link

yschimke commented Jan 1, 2022

Working around with

task copyJvmJar(type: Copy) {
  def sourceFile = project.tasks.getByName("jvmJar").outputs.files.singleFile
  def destFile = project.tasks.getByName("jar").outputs.files.singleFile
  from sourceFile
  into destFile.parentFile
  rename (sourceFile.name, destFile.name)
}

tasks.getByName("copyJvmJar").dependsOn(jvmJar)
tasks.getByName("nativeImage").dependsOn(copyJvmJar)

@yschimke
Copy link

Advice on gradle/gradle#19449 seems to be assume a default of the jar plugin, but always allow overriding this in the plugin config.

@yschimke
Copy link

With a kts build file.

val copyJvmJar = tasks.register<Copy>("copyJvmJar") {
  val sourceFile = project.tasks.getByName("jvmJar").outputs.files.singleFile
  val destinationFile = project.tasks.getByName("jar").outputs.files.singleFile
  from(sourceFile)
  into(destinationFile.parentFile)
  rename (sourceFile.name, destinationFile.name)
}

tasks.getByName("copyJvmJar").dependsOn(tasks.getByName("jvmJar"))
tasks.getByName("nativeImage").dependsOn(copyJvmJar)

@yschimke
Copy link

Looks like the classpath needs to be jvmRuntimeClasspath not runtimeClasspath here

task.setClasspath(project.getConfigurations().named("runtimeClasspath"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants