Jack J
Jack J

Reputation: 1644

Gradle jlink options gives access rights warning

Using Gradle, this is a very common script for jlink:

plugins {
    id 'application'
    id "org.beryx.jlink" version "2.16.3"
}

jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'helloFX'
    }
}

For a reason unknown to me, IntelliJ always gives me this warning for options:

Access to 'options' exceeds its access rights. Cannot assign a value to final field 'options'.

And a warning for ['--strip-debug', '--compress', ... ]:

Cannot apply default constructor for class 'ListProperty'.

I don't know what is causing it. This is pretty much a copy-paste from gluon's javafx help, though my project is multimodule. I don't see why that would change anything. Everything else in gluon's script works fine. jlink even creates a launcher with the name 'helloFX' which works. I don't know how I might check to see if any of the options are working. I would imagine they are not.

Upvotes: 3

Views: 782

Answers (1)

user437212
user437212

Reputation:

This seems to be warning that jlink.options is final, and the options == [] format is actually an implicit constructor. This is a problem because the options are already created when the jlink extension is created.

Or, it seems that way, but it is probably a bug in IDEA's Gradle support for custom plugins.

But, since it is already created, can we use the setter as a workaround?

options.set([ '--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages' ])

This seems to work to remove the warning in the IDE. There is also an addOptions method exposed, so we could probably do this as well:

addOptions('--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages')

This latter convenience seems to be the same as options.addAll() but with some sanity checks. To me, it seems more Groovy.

Upvotes: 2

Related Questions