gradle-ospackage-plugin
gradle-ospackage-plugin copied to clipboard
Usage with Gradle Kotlin DSL
The plugin makes use of additional properties on CopySpec
s, added through a Groovy category and meta class.
It's possible to use them in Gradle Kotlin DSL by calling the category directly:
val rpm by tasks.creating(Rpm::class) {
from("src/systemd/") {
into("/lib/systemd/system")
CopySpecEnhancement.createDirectoryEntry(this, false)
}
// …
It becomes a bit more complicated with fileType
when you want to combine flags (which uses the metaClass of Directive
):
val rpm by tasks.creating(Rpm::class) {
from("src/etc/") {
into("/etc/$packageName")
CopySpecEnhancement.fileType(Directory(Directory.RPMFILE_CONFIG or Directory.RPMFILE_NOREPLACE))
}
// …
At a minimum, this should be documented; but it would be even better if the plugin could provide Kotlin extensions that would do the same:
var CopySpec.fileType: Directive
get() = withGroovyBuilder { "getFileType"() as Directive }
set(value) = CopySpecEnhancement.fileType(this, value)
fun CopySpec.fileType(value: Directive): Unit =
CopySpecEnhancement.fileType(this, value)
// …and similar for other properties…
infix fun Directive.or(other: Directive): Directive =
Directive(this.flag() or other.flag())
(I did something similar in my net.ltgt.apt
plugin if you want to look at how I did: I created a subproject specific to the Kotlin extensions –because the kotlin
plugin configures compileJava
to depend on compileKotlin
, where I need the reverse– and copy the classes into the final JAR of the plugin)
For now, I'm using the above snippet into my *.gradle.kts
build script.
The most confusing is that this code does not throw error:
...
from ("test.txt") {
fileMode = 0b000_101_101_000
fileType = Directive(Directive.RPMFILE_CONFIG or Directive.RPMFILE_NOREPLACE)
user = "root"
permissionGroup = "adm"
}
It does set fileMode as expected, but it won't set fileType, user and permissionGroup for a file, but instead on a SystemPackagingExtension, which has these fields.
Not elegant, but working solution I use:
import com.netflix.gradle.plugins.packaging.CopySpecEnhancement.*
...
from ("test.txt") {
fileMode = 0b000_101_101_000
setFileType(this, Directive(Directive.RPMFILE_CONFIG or Directive.RPMFILE_NOREPLACE))
setUser(this, "root")
setPermissionGroup(this, "adm")
}
Thanks @tbroyer for a hint.
nebula.rpm with kotlin-dsl is completely broken on [email protected]. Rpm package properties are not set, e.g. packageName = "test" does not throw any error, however does not set package name either.
Is there any news about this? This bug makes it feel like the plugin is abandonware
Unfortunately, there is no news. RPM and Kotlin DLS are not used for most of our users so we prioritize different work. It is very likely that RPM support will get removed eventually from the plugin.
WRT to RPM it's sad to hear. Looking at the open tickets, 23 out of 52 is RPM-related, so it seems that there is interest in using RPM packaging. I myself also use rpm-packaging from this plugin. Maybe I could help with both Kotlin DSL and RPM support?
If the community would like to pickup the maintenance of the rpm packaging we'd certainly land pull requests - but the reason you see mostly open rpm tickets is that we don't use rpm support ourselves so can't prioritize addressing those issues.