Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mrcjkb opened this issue Nov 25, 2020 · 5 comments

Comments

@mrcjkb
Copy link

mrcjkb commented Nov 25, 2020

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
Copy link
Author

mrcjkb commented Dec 3, 2020

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).

@falkoschumann
Copy link

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.

@mrcjkb
Copy link
Author

mrcjkb commented Jan 6, 2021

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) }
    }
}

@abhinayagarwal
Copy link
Collaborator

abhinayagarwal commented Mar 11, 2021

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.

@mrcjkb
Copy link
Author

mrcjkb commented Mar 11, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants