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

task `jpackage` is not safe for multiple execution of gradle target #29

Closed miurahr closed 11 months ago

miurahr commented 11 months ago

Gradle tasks should be safe for multiple target executions. The task jpackage is always executed and went to failure.

It is because task jpackage is not up-to-date because the task has not declared any outputs despite executing actions. OpenJDK jpackage command assumes that target directory is not exist when executed. When multiple execution of gradle jpackage cause error because target folder already exists.

The task should report output files to gradle core then gradle can detect up-to-date status. It can be said for other tasks that are registered from JPackageTask type.

You can find a log like as follows;

jpackage output:
エラー: アプリケーションの宛先ディレクトリ build/jpackage/app-image/OmegaTはすでに存在します

jpackage output:
Error: Application target  directory  build/jpackage/app-image/OmegaT has already exist.
miurahr commented 11 months ago

To workaround the error, I crafted a task

// clean work folder for jpackage
def jpackageWorkdir = layout.buildDirectory.file('jpackage')
tasks.register('cleanJpkgWorkdir', Delete) {
    delete jpackageWorkdir
}
tasks.jpackage {
    dependsOn cleanJpkgWorkdir
}

Because jpackage does not support a build cache, which means always not-up-to-date, so the clean and build task are invoked.

petr-panteleyev commented 11 months ago

Either that or simply use clean with jpackage. It does not hurt to have a clean build before making a distribution.