Reeves
Reeves

Reputation: 43

Gradle Multi-Modular, Sub-Project can't see dependencies

The project structure is below with MyProject as the root project and DataManager and FileManger as the sub-projects. The root project includes both sub-projects and DataManger include FileManager. The issue is DataManager's dependencies are not visible, so it says. MyProject has the same issue when DataManager is imported. The errors are all similar to this one:

C:\Users\XX\XX\XX\MyProject\DataManager\src\main\java\DataManager\DataManager.java:15: error: package org.yaml.snakeyaml is not visible
import org.yaml.snakeyaml.Yaml;
               ^
  (package org.yaml.snakeyaml is declared in the unnamed module, but module org.yaml.snakeyaml does not read it)

.

MyProject
   \build.gradle
    settings.gradle
    src
       \main
           \java
               \module-info.java
                MyProject
                    \App.java
   \DataManager
      \build.gradle
       src
          \main
              \java
                  \module-info.java
                   DataManager
                       \DataManager.java
   \FileManger
      \build.gradle
       src
          \main
              \java
                  \module-info.java
                   FileManger
                       \FileManger.java

MyProject Build:

plugins {
    id 'java'
    id 'application'
    id 'groovy'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.beryx.jlink' version '2.12.0'
}

javafx {
    version = "13"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

mainClassName = "$moduleName/MyProject.App"

jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'MyProject'
    }
}

repositories {
    jcenter()
}

dependencies {
    implementation 'com.google.guava:guava:28.1-jre'

    testImplementation 'org.codehaus.groovy:groovy-all:2.5.8'

    testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
    testImplementation 'junit:junit:4.12'

    compile project (':DataManager')
    compile project (':FileManager')
}

application {
    mainClassName = 'MyProject.App'
    mainClassName = "$moduleName/MyProject.App"
}

MyProject module-info:

module MyProject{
    requires javafx.fxml;
    requires javafx.controls;
    requires DataManager;

    opens MyProject to javafx.fxml;
    exports MyProject;
}

DataManger build:

plugins {
    id 'java'
    id 'groovy'
}

repositories {
    jcenter()
}

dependencies {
    implementation 'com.google.guava:guava:28.1-jre'

    // Use SnakeYAML
    implementation group: 'org.yaml', name: 'snakeyaml', version: '1.25'

    testImplementation 'org.codehaus.groovy:groovy-all:2.5.8'

    testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
    testImplementation 'junit:junit:4.12'

    compile project(':FileManager')
}

DataManager module-info:

module DataManager{
    requires FileManager;
    requires snakeyaml;

    exports DataManager;
}

FileManager build:

plugins {
    id 'java'
    id 'groovy'
}

repositories {
    jcenter()
}

dependencies {
    implementation 'com.google.guava:guava:28.1-jre'

    testImplementation 'org.codehaus.groovy:groovy-all:2.5.8'

    testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
    testImplementation 'junit:junit:4.12'
}

FileManager module-info:

module FileManager{
   exports FileManager;
}

Upvotes: 1

Views: 415

Answers (1)

Reeves
Reeves

Reputation: 43

Remove the module-info.java files when using Gradle.

Upvotes: 1

Related Questions