Gradle build - add module path

后端 未结 3 1759
失恋的感觉
失恋的感觉 2021-01-13 08:25

My question: How do I set a module path for gradle build?

I\'ve become comfortable working with Java modules from the command line. I do a frequent exe

3条回答
  •  误落风尘
    2021-01-13 08:40

    First please note: I am on Gradle 6.6.1 with Java 15.

    This is what I have observed:

    1. in order to make the compile work, every project needs:

      java {
          modularity.inferModulePath = true
      }
      
    2. this can be turned on at root build.gradle via

       subprojects {
           apply plugin: "java"
           java {
               modularity.inferModulePath = true
           }
       }
      
    3. in order to use modulepath with gradle run (ServiceLoader working WITHOUT META-INF, reflection restrictions ...) you have to use following application section:

      application {
           mainModule = 'org.gradle.sample.app' // name defined in module-info.java
           mainClass = 'org.gradle.sample.Main'
           // DO NOT USE   mainClassName = 'org.gradle.sample.Main'
      }
      

    Took me quite some time to put all together from several Gradle pages --- but it is all here.

    Note:

    This will not but non-modular jars to the module-path.

提交回复
热议问题