mike-neck / graalvm-native-image-plugin

A Gradle plugin which creates a native executable via GraalVM's native-image. This is a thin wrapper of the native-image command.
Apache License 2.0
89 stars 14 forks source link

Depricated "mainClass" property is necessary for "generateNativeImageConfig" to work #175

Open wgryglas opened 3 years ago

wgryglas commented 3 years ago

Describe What happened

When trying to run generateNativeImage task gradle complains about Property mainClass not being initialized. The mainClass under the "nativeImage" is set via buildType { buidl->build.executable(...) }.

How To Reproduce

The following gradle.build.kts configuration causes problem unless you uncomment "mainClass = mainClassPathName"

[....]
nativeImage {
    // mainClass = mainClassPathName     ---> without this line gradle plugin can not run
    graalVmHome = getGraalVmHome()
    buildType { build ->
        build.executable {
            main = mainClassPathName
        }
    }
    executableName = project.name
    outputDirectory = file("$buildDir/$nativeImageDirName")
    arguments(
        "--no-fallback",
        "--initialize-at-run-time=org.lwjgl",
        "--native-image-info",
        "--verbose",
        "-H:TempDirectory=$buildDir/tmp/$nativeImageDirName"
    )
}
generateNativeImageConfig {
    enabled = true
    graalVmHome = getGraalVmHome()
    byRunningApplicationWithoutArguments()
}

Environment

KengoTODA commented 3 years ago

I met the same issue in my build, here is its log from my workflow run:

Some problems were found with the configuration of task ':generateNativeImageConfig' (type 'DefaultGenerateNativeImageConfigTask').
  - In plugin 'org.mikeneck.graalvm-native-image' type 'org.mikeneck.graalvm.DefaultGenerateNativeImageConfigTask' property 'javaExecutions.$0.mainClass' doesn't have a configured value.

    Reason: This property isn't marked as optional and no value has been configured.

    Possible solutions:
      1. Assign a value to 'javaExecutions.$0.mainClass'.
      2. Mark property 'javaExecutions.$0.mainClass' as optional.

    Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#value_not_set for more details about this problem.