krakowski / gradle-jextract

Gradle plugin for integrating Project Panama's jextract tool
https://plugins.gradle.org/plugin/io.github.krakowski.jextract
GNU General Public License v3.0
53 stars 10 forks source link

Cannot be used with gradle kotlin DSL #20

Closed rongcuid closed 8 months ago

rongcuid commented 8 months ago

Environment

How does this bug occur?

Trying to make a new project with gradle kotlin DSL:

import io.github.krakowski.jextract.JextractPlugin
import io.github.krakowski.jextract.JextractTask
import io.github.krakowski.jextract.LibraryDefinition

plugins {
    kotlin("jvm") version "1.9.22"
    id("application")
    id("c")
    id("io.github.krakowski.jextract") version "0.4.1"
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation("org.jetbrains.kotlin:kotlin-test")
}

tasks.test {
    useJUnitPlatform()
}
kotlin {
    jvmToolchain(21)
}

configure<JextractTask> {
    // The header file from which we want to generate the bindings
    header("${project.projectDir}/src/main/c/native.h") {
        // The library name (don't worry about this for now)
        libraries = arrayOf("nativeLib")
        // The package under which all source files will be generated
        targetPackage = "org.nativelib"
        // The generated class name
        className = "NativeLib"
    }
}

What happens when the bug occurs?

When trying to configure jextract class, Val cannot be reassigned occurs.

Would you like to submit a PR fixing this bug?

[ ] YES [x] NO

rongcuid commented 8 months ago

Never mind, the real problem is I have no idea how gradle works.

The correct configuration (probably) is:

tasks.jextract {
    // The header file from which we want to generate the bindings
    header("${project.projectDir}/src/main/c/native.h") {
        // The library name (don't worry about this for now)
        libraries = listOf("nativeLib")
        // The package under which all source files will be generated
        targetPackage = "org.nativelib"
        // The generated class name
        className = "NativeLib"
    }
}

Maybe the author can clarify how the plugin is supposed to be used in the kotlin dsl? I am still not 100% sure.

krakowski commented 8 months ago

Hi @rongcuid,

Thanks for bringing this to my attention. I converted the demo project to Kotlin DSL, so that it's easier to get started.

Please let me know if this helps with your issue :slightly_smiling_face:

krakowski commented 8 months ago

Closing due to inactivity