Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Java 9 Module not found

I try to develop a little example in Java 9 with Gradle. But I don't find the exact option to make a working run config. I've tried to copy the right parts from this little tutorial. But the run task does just get an error

java.lang.module.FindException: Module de.project.crawler not found

Obviously there is a mistake with the module path which I gave Gradle but I don't know how to fix this.

My working directory

project/
  crawler/
  |  src/
  |  |  main/
  |  |  |  java/
  |  |  |  |  de.project.crawler/
  |  |  |  |  |  Main.java
  |  |  module-info.java
  |  build.gradle
  |  settings.gradle
  build.gradle
  settings.gradle

build.gradle:

subprojects {
    afterEvaluate {
        compileJava {
            inputs.property("moduleName", moduleName)
            doFirst {
                options.compilerArgs = [
                        '--module-path', classpath.asPath,
                ]
                classpath = files()
            }
        }
    }
}

crawler/build.gradle:

plugins {
    id 'java-library'
    id 'application'
}

ext.moduleName = 'de.project.crawler'
mainClassName = 'de.project.crawler/de.project.crawler.Main'

repositories {
    jcenter()
}

run {
    inputs.property("moduleName", moduleName)
    doFirst {
        jvmArgs = [
                '--module-path', classpath.asPath,
                '--module', mainClassName
        ]
        classpath = files()
    }
}

startScripts {
    inputs.property("moduleName", moduleName)
    doFirst {
        classpath = files()
        defaultJvmOpts = [
                '--module-path', 'APP_HOME_LIBS',
                '--module', mainClassName
        ]
    }
}

crawler/src/module-java.info

module de.project.crawler {
}

crawler/src/main/java/de.project.crawler/Main.java

package de.project.crawler;

public class Main {

    public static void main(String[] args) {
        System.out.println("Hallo");
    }
}

So, if I try this in IntelliJ everything is working. If I try this on cmd, compile with java9 and run it, everything is working. If I try 'gradle run' he states the error which I gave you in the introduction.

like image 760
BeJay Avatar asked Mar 06 '23 21:03

BeJay


1 Answers

The module-info.java was on the wrong position. This file has to be on src/main/java in the module. This is the right structure:

project/
  crawler/
  |  src/
  |  |  main/
  |  |  |  java/
  |  |  |  |  de.project.crawler/
  |  |  |  |  |  Main.java
  |  |  |  |  module-info.java
  |  build.gradle
  |  settings.gradle
  build.gradle
  settings.gradle

Thanks Alan Bateman from the comments.

like image 179
BeJay Avatar answered Mar 10 '23 11:03

BeJay