1

In Gradle 6.3 within build.gradle, mainClassName may be set like this with no complaints:

mainClassName = 'mod/app.Main'

In Gradle 6.61, the above line results in this:

java.lang.module.InvalidModuleDescriptorException: Package mod.app not found in module

This can be resolved by removing the module portion of mainClassName:

mainClassName = 'app.Main'

While the exception is resolved, Gradle still states:

No module was provided for main class, assuming the current module. Prefer providing 'mainClassName' in the following format: '$moduleName/a.b.Main'

I have experimented with variations of this:

ext.moduleName = 'mod'
mainClassName = '${ext.moduleName}/app.Main'

So far I have been unable to get any of these to work. I could work with the setting as 'app.Main', but I would prefer to use the variation that Gradle prefers. How should this be done?

Jack J
  • 1,514
  • 3
  • 20
  • 28

2 Answers2

1

Gradle 6.3 doesn't support JPMS, but 6.4+ does. So I assume you are using the 3rd party gradle-modules-plugin. For this plugin, you need to use version 1.7.0 or later for supporting newer versions of Gradle.

Alternatively, remove the plugin and use the native support in Gradle. Right now it looks like you are a mix of the two at the same time.

Bjørn Vester
  • 6,851
  • 1
  • 20
  • 20
  • The plugins I am using are `application`, `javaFX 0.0.8`, and `jlink 2.22.0`. I suspect that the javaFX plugin is providing JPMS support. There is a newer 0.0.9 version available, but using this new version causes this: `org.joor.ReflectException: java.lang.NoSuchFieldException: javaExecHandleBuilder`. Based on your answer then, is this likely an issue caused by the JavaFX plugin? – Jack J Sep 17 '20 at 14:47
  • 1
    Actually the JavaFX plugin automatically applies the module plugin I linked to. But there is also an open issue on JavaFX relating to Gradle 6.6 (see [here](https://github.com/openjfx/javafx-gradle-plugin/issues/89)) related to the ReflectException you mention. So you may need to wait until they fix it, or go with Gradle 6.5 in the meantime. – Bjørn Vester Sep 18 '20 at 08:05
1

work in 6.3 mainClassName = "$moduleName/app.Main"

work in 6.4+


run {
    main = "$moduleName/app.Main"
}

Steven Sun
  • 871
  • 5
  • 4