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

JavaFX plugin forces Gradle to put libraries on the modulepath instead of the classpath

Open mrcjkb opened this issue 4 years ago • 5 comments

How to reproduce:

  • Gradle version 6.7.1
  • JavaFX plugin version 0.0.9

Given a modular project with a module-info.java in its main root. And the following Gradle config:

java {
  modularity.inferModulePath.set(true)
  toolchain {
    languageVersion.set(JavaLanguageVersion.of(11))
  }
}

And a non-modular test dependency, e.g. testImplementation("com.tngtech.archunit:archunit-junit5:0.14.1")

And a test case, e.g.

@AnalyzeClasses(packages = "*", importOptions =  { ImportOption.DoNotIncludeTests.class })
public class ArchitectureTest {
    @ArchTest
    public static final ArchRule CYCLE_RULE = slices().matching("..(*)..").should().beFreeOfCycles();
}

When I run the test case with Gradle 6.7.1

Expected behaviour: Then the test case runs Current behaviour: Then the test case does not run, due to a java.lang.module.ResolutionException

mrcjkb avatar Nov 25 '20 20:11 mrcjkb

I believe this plugin no longer needs to depend on the modularity plugin, which appears to be the cause of this issue (as of Gradle 6.4).

mrcjkb avatar Dec 03 '20 20:12 mrcjkb

As workaround, remove javafx-gradle-plugin and add JavaFX manually:

def openjfxGroup = 'org.openjfx'
def openjfxVersion = '15.0.1'
def osName = System.properties['os.name'].toLowerCase()
def openjfxPlatform = osName.contains('mac') ? 'mac' : osName.contains('win') ? 'win' : osName.contains('linux') ? 'linux' : null

dependencies {
  api(group: openjfxGroup, name: 'javafx-base', version: openjfxVersion, classifier: openjfxPlatform)
  api(group: openjfxGroup, name: 'javafx-graphics', version: openjfxVersion, classifier: openjfxPlatform)
  api(group: openjfxGroup, name: 'javafx-controls', version: openjfxVersion, classifier: openjfxPlatform)
}

java {
  modularity.inferModulePath = true
}

This works with Gradle 6.7. All used JavaFX modules must be added because transitiv dependencies are not solved automatically. For my use case, the javafx-gradle-plugin should only resolve transitive dependencies of JavaFX module and platform.

falkoschumann avatar Jan 05 '21 20:01 falkoschumann

Thanks. Heres is another workaround (I haven't tested it with the javafx plugin, but it works with another plugin that has the same issue), so it should work with this one too.

configurations {
    testRuntimeClasspath {
        attributes { attribute(Attribute.of("javaModule", Boolean::class.javaObjectType), false) }
    }
    testCompileClasspath {
        attributes { attribute(Attribute.of("javaModule", Boolean::class.javaObjectType), false) }
    }
}

mrcjkb avatar Jan 06 '21 19:01 mrcjkb

Hi @MrcJkb ,

Would you be interested in creating a PR for the plugin to remove its dependency on the modularity plugin when used with Gradle 6.4 and later.

abhinayagarwal avatar Mar 11 '21 17:03 abhinayagarwal

Sure. I'll look into it when I have some time.

mrcjkb avatar Mar 11 '21 18:03 mrcjkb