1. Danno Ferrin
  2. javafx-gradle
  3. Issues
Issue #13 invalid

CSS Image/Resource Path Broken If Built with Gradle

Michael Hoffer
created an issue

If I build my project with gradle it does use absolute paths for css image urls. Images cannot be found if deployed application runs on different user account. If built via NetBeans and Ant the problem does not occur.


  • OS: Mac OS 10.8.3
  • Java: 1.7.0u13
  • NetBeans: 7.3
  • Gradle: 1.6


I created a sample project to demonstrate the issue: https://www.dropbox.com/sh/0u5c81iqafmczq7/KrJGHNt5uT

It contains the gradle project and a NetBeans project as reference. The CSS file references images like so:

-fx-background-image: url("button-off-01.png");

How to reproduce:

cd gradle-bugreport/JavaFXCSSBug01-gradle
./gradlew clean assemble

Now start the application. It should run as expected:

open build/distributions/bundles/JavaFXCSSBug01-gradle.app

If the original resource location is moved the application will not show the styled button:

mv src src2

Now start the application. It should NOT run as expected:

open build/distributions/bundles/JavaFXCSSBug01-gradle.app

The button image is missing.

Comments (2)

  1. Danno Ferrin repo owner

    This is ultimately a gradle configuration bug. Because the java source set and resources source set overlapped in files, the files in both source sets went to the java soruce set and not the resources source set.

    My principal recommendation is to move the files and use the conventional directory layouts of src/main/java and arc/main/resources and don't alter the source set configurations. This keeps compiled code in a separate tree from copied code. I strongly recommend this corse of action above all else.

    My alternate reccomendation is to make the includes/excludes explicit in the source sets, like so:

    sourceSets {
        main {
            java {
                srcDirs = ['src/']
            include '**/*.java'
            resources {
                srcDirs = ['src/']
            exclude '**/*.java'
        test {
            java {
                srcDirs = ['test/']
            include '**/*.java'

    However, the path of least resistance is to adopt the standard directory layout of src/main/java, src/main/resources, src/test/java, and src/test/resources

  2. Michael Hoffer reporter

    This is ultimately a gradle configuration bug.

    Even though the gradle config of the example was indeed problematic, the bug is not caused by the config. It seems to be a problem with the cssToBin task which sometimes uses absolute paths instead of relative. Currently, I don't have the problem anymore (with JDK 8).

  3. Log in to comment