petr-panteleyev / jpackage-gradle-plugin

JPackage Gradle Plugin
https://codeberg.org/petr-panteleyev/jpackage-gradle-plugin
BSD 2-Clause "Simplified" License
97 stars 13 forks source link

Proposal: accept mainClass property from `application.mainClass` reference #31

Closed miurahr closed 9 months ago

miurahr commented 9 months ago

Problem

Configure jpackage task using application.mainClass property like

tasks.jpackage {
    mainClass = application.mainClass
} 

then the application is failed to launch with error

pure virtual method called
terminate called without an active exception
Error: Can not detect and load a main class "extension 'application' property 'mainClass'" 
Cause: java.lang.ClassNotFoundException: extension 'application' property 'mainClass'

investigation

Because Gradle 8.x deprecated an application convention, and mainClassName = 'java.class.name' String syntax is replaced to application.mainClass = 'java.main.class' by application plugin and it can be referenced by application.mainClass.

JavaApplication#getMainClass returns Property<String>, but jpackage plugin does not accept Property object.

similar case that works well in Gradle

You may know that JavaExec task can take a property in similar syntax such as

tasks.register('debug', JavaExec) {
    mainClass = application.mainClass
    classpath = sourceSets.main.runtimeClasspath
    debug true
}

JavaExec class in Gradle project source defines parameters like

  public JavaExec() {
        ObjectFactory objectFactory = getObjectFactory();
        mainModule = objectFactory.property(String.class);
        mainClass = objectFactory.property(String.class);

then it can accept the syntax.

Here is a proposal to change internal variables from String to Provider<String>, and change references to object.get().

User side solution

User can avoid a problem when using jpackage

mainClass = application.mainClass.get()

rather than a way JavaExec accepts.

petr-panteleyev commented 9 months ago

That's definetly not a plugin issue. Plugin expects string here. How this string is produced is totally up to the build script.