I'm getting a 'header file doesn't exist' error when using the Hierynomus Gradle License Plugin with build.gradle.kts

I’m trying to configure the Hierynomus Gradle License Plugin in my build.gradle.kts file, but I keep encountering the error:

A problem was found with the configuration of task ':licenseMain' (type 'LicenseCheck').
- In plugin 'com.hierynomus.gradle.license.LicenseBasePlugin' type 'com.hierynomus.gradle.license.tasks.LicenseCheck' property 'header' specifies file 'F:\Kod\Java\Plugin\mFly\LICENSE' which doesn't exist.`

It seems like the plugin isn’t saving or applying the header variable correctly, and it expects a file that doesn’t exist. Here’s my build.gradle.kts file:

import nl.javadude.gradle.plugins.license.LicenseExtension

plugins {
    id("java")
    id("com.github.hierynomus.license") version "0.16.1"
}

defaultTasks("licenseFormat", "build")

subprojects {
    apply(plugin = "java")
    apply(plugin = "com.github.hierynomus.license")

    group = "me.makalidap.mfly"
    version = "0.1-SNAPSHOT"

    java {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    tasks {
        withType<JavaCompile>().configureEach {
            options.encoding = "UTF-8"
        }

        jar {
            from("${project.rootDir}/LICENSE.txt")
        }
    }

    configure<LicenseExtension> {
        header = file("${project.rootDir}\\HEADER.txt")
    }


    repositories {
        mavenCentral()
    }
}

I’ve also tried these alternatives, but they did not solve the issue:

license {
   header = file("${project.rootDir}\\HEADER.txt")
}

header = rootProject.file("HEADER.txt")

I printed out paths to ensure correctness, and I’ve tried running the build with both Java 8 and Java 17, but the issue persists.
Here’s the full error message:

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':licenseMain' (type 'LicenseCheck').
- In plugin 'com.hierynomus.gradle.license.LicenseBasePlugin' type 'com.hierynomus.gradle.license.tasks.LicenseCheck' property 'header' specifies file 'F:\Kod\Java\Plugin\mFly\LICENSE' which doesn't exist.
  
    Reason: An input file was expected to be present but it doesn't exist.

    Possible solutions:
      1. Make sure the file exists before the task is called.
      2. Make sure that the task which produces the file is declared as an input.

I’m using Gradle 8.8. Any suggestions on what could be going wrong?

I’m not particularly attached to this plugin, so if you have recommendations for alternative plugins that handle license checks, I would be happy to try them!

You apply the plugin to all projects, but only set the header property on the subprojects.
So on the root project it still has its default value (I guess) and the root project’s task instance also is what it complains about.


Besides that, you should strongly consider refactoring your build logic to get rid of all the bad practice.
For example:

  • Do not do any cross-project configuration like subprojects { ... }, allprojects { ... }, project(...) { ... }, or any other means of cross-project configuration, but instead use convention plugins, for example in buildSrc or an included build, for example implemented as precompiled script plugin.
  • Do not use the legacy apply(...) way of applying plugins, but always the plugins { ... } block
  • Then you also do not need to use clumsy configure<...> { ... } constructs but can use the proper type-safe accessors.