While migration process from Gradle Groovy to Grad...
# gradle
a
While migration process from Gradle Groovy to Gradle Kotlin DSL, I was migrating a plugin that was written in Gradle Groovy (for this example https://github.com/CadixDev/licenser) but support the
plugins
block, to configure it in Gradle groovy you simply have to use:
Copy code
license {
    header = project.file('LICENSEHEADER')
}
So I used this in Gradle Kotlin DSL:
Copy code
configure<org.cadixdev.gradle.licenser.LicenseExtension> {
    setHeader(project.file("LICENSEHEADER"))
}
since I'm applying the plugin using the
plugins
block then should use this instead:
Copy code
license {
    setHeader(project.file("LICENSEHEADER"))
}
As an alternative, but the problem is the configurations doesn't seems to be applied in the Gradle Kotlin DSL one because when running the task that use those configurations (
./gradlew licenseCheck
) it will always success even if there was a file that doesn't append the LICENSE at the start of the file, this wasn't in issue in Gradle Groovy code, any ideas or is it a issue from the plugin side?
v
If you use the
plugins { ... }
block (and there are only very few and seldom cases where you cannot) why do you need to use
configure
?
a
Well, I tried out both and both doesn't apply the configuration like expected
v
You are aware that in the Groovy version you use
HEADER.txt
while in the Kotlin version you use
LICENSEHEADER
?
a
This was an example (I copied it from the docs) but in the project I'm migrating the file is the exact same. (since you mentioned it, I updated the message to be more clear for everyone)
v
Ah, I see
So yeah,
Copy code
license {
    setHeader(project.file("LICENSEHEADER"))
}
or
Copy code
license {
    header(project.file("LICENSEHEADER"))
}
in Kotlin DSL should behave like
Copy code
license {
    header = project.file('LICENSEHEADER')
}
in Groovy DSL
Maybe you also here changed something more, like the version of the plugin or similar?
a
I usually make it so PRs are structured in a way so it only does what it aim for and doesn't fix or change anything else, if there is a fix that is not related then it will be in a different PR, I just checked it now and it didn't changed the plugin version but there might be something else, I will try to debug and find it out, I appreciate your help
👌 1
So there was some other configurations in the project (not by me, I didn't touch it or created it):
Copy code
include("'**/*.java'")
    exclude("io/github/**/*.java")
    exclude("net/minecraft/**/*.java")
    exclude("com/atlauncher/graphql/**/*.java")
    exclude("com/atlauncher/gui/layouts/WrapLayout.java")
    newLine = false

    ext.set("year", currentYear())
And after removing them and make it minimal it worked (it throw an error), but I'm not sure why this is needed, on Gradle groovy that's wasn't needed, I'm pretty sure they added those configurations for a reason, because I'm getting on multiple errors for different files instead of the newly created one that doesn't have the License Header in the start of the file, so it's a configuration issue and the plugin work just like expected but I'm not sure why their configurations work like expected only on Gradle Groovy code, I update the syntax and didn't touch anything else The old Groovy code:
Copy code
license {
    header = project.file('LICENSEHEADER')
    include '**/*.java'
    exclude 'io/github/**/*.java'
    exclude 'net/minecraft/**/*.java'
    exclude 'com/atlauncher/graphql/**/*.java'
    exclude 'com/atlauncher/gui/layouts/WrapLayout.java'
    newLine = false
    properties {
        year = currentYear()
    }
}
It could be the issue with the properties, so it's an issue from my side or the project side, not really from the plugin. I couldn't find the alternative of
Copy code
properties {
        year = currentYear()
    }
in Gradle Kotlin DSL
After some testing, it appear it was an issue from my side, the correct include is
include("**/*.java")
still not sure on how how set the year property in the
propeties
block as the
year
doesn't exist when using Gradle Kotlin DSL
v
Probably
Copy code
properties {
    set("year", currentYear())
}
a
That's strange, I'm sure I tried this before but it didn't work and now it did, maybe because I was using configure instead of directly using the plugin configurations?
🤷‍♂️ 1