javafx-gradle-plugin icon indicating copy to clipboard operation
javafx-gradle-plugin copied to clipboard

configuration = 'compileOnly' breaks unit tests of library module

Open msgilligan opened this issue 5 years ago • 8 comments

I added

configuration = "compileOnly"

to my java-library module (in a multi-project gradle build) and now my (Spock) unit tests are failing because they can't find JavaFX classes.

I don't understand the internals of this plugin, but what I think I want is an api configuration for the cross-platform JavaFX jars and a testRuntimeOnly configuration for the platform-specific jars.

msgilligan avatar Jul 14 '20 19:07 msgilligan

This is not related to the plugin but how Gradle treats these dependency configurations. In Gradle, compileOnly dependencies are not available to test and you need to add the same dependencies to testCompileOnly.

However, the plugin doesn't allow you to declare more than one "configuration" atm and we would want to change this in the future.

abhinayagarwal avatar Oct 02 '20 08:10 abhinayagarwal

However, the plugin doesn't allow you to declare more than one "configuration" atm and we would want to change this in the future.

Yes, this is essentially what I was asking for.

Although I'm building a library, so I'd also like the ability to make the JavaFX dependency Gradle api dependencies.

msgilligan avatar Oct 17 '20 00:10 msgilligan

@abhinayagarwal

I'd like to declare something like this:

javafx {
    version = '15'
    modules = [ 'javafx.graphics', 'javafx.fxml' ]
    configurations = ['api', 'testImplementation']
 }

Which would effectively generate something like this:

    api "org.openjfx:javafx-graphics:${javaFxVersion}"
    api "org.openjfx:javafx-fxml:${javaFxVersion}"

    compileOnly "org.openjfx:javafx-base:${javaFxVersion}:${platformClassifier}"
    compileOnly "org.openjfx:javafx-graphics:${javaFxVersion}:${platformClassifier}"
    compileOnly "org.openjfx:javafx-fxml:${javaFxVersion}:${platformClassifier}"

    testImplementation "org.openjfx:javafx-base:${javaFxVersion}:${platformClassifier}"
    testImplementation "org.openjfx:javafx-graphics:${javaFxVersion}:${platformClassifier}"
    testImplementation "org.openjfx:javafx-fxml:${javaFxVersion}:${platformClassifier}"

I want my library to be able to declare (for purposes of generating its POM) its direct JavaFX dependencies (graphics and fxml) and have the plugin make sure the transitive native dependencies (in this case base) are included for both compileOnly and testImplementation.

msgilligan avatar Oct 21 '20 22:10 msgilligan

@abhinayagarwal @jperedadnr

Are there any updates on support for a second configuration, such as testCompile or testImplementation ?

I had a workaround solution for this issue, but upgrading to OpenJFX 17 and version 0.0.10 of the plugin seems to have broken my little (internal) Gradle plugin.

See https://github.com/SupernautApp/SupernautFX/issues/19 for details.

msgilligan avatar Sep 09 '21 23:09 msgilligan

@abhinayagarwal JavaFX 17.0.0.1 allows me to use my workaround to this issue (i.e. not using the Gradle plugin at all) but this improvement is still needed for JavaFX library developers to be able to use this plugin.

The proposed changes to the way the JARs will be packaged in Java FX 18, should help with this issue as well. (They should also make it easier to reference the JARs in Gradle builds without any plugin)

msgilligan avatar Sep 16 '21 18:09 msgilligan

PR #115 looks like it might be a solution for this problem.

msgilligan avatar May 25 '22 19:05 msgilligan

PR #115 looks like it might be a solution for this problem.

msgilligan avatar May 25 '22 19:05 msgilligan

PR #137 and release 0.0.14 look promising. I will try them for the next release of SupernautFX and verify that the correct dependencies are published with the artifacts.

msgilligan avatar Jul 16 '23 00:07 msgilligan