Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java 9 module reads package X from A and B

I am trying to use spring boot with java 9 and gradle. I am unable to run my simple code, I get the below mentioned error :-

Information:java: Errors occurred while compiling module 'Java9Gradle_main'
Information:javac 9-ea was used to compile java sources
Information:6/9/2017 10:40 PM - Compilation completed with 65 errors and 0 warnings in 15s 200ms
Error:java: module  reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module  reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.web reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.web reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.autoconfigure reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.autoconfigure reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.logging reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.logging reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.core reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.core reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module snakeyaml reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module snakeyaml reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.tomcat reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter.tomcat reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module hibernate.validator reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module hibernate.validator reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jackson.databind reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jackson.databind reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.web reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.web reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.webmvc reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.webmvc reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.context reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.context reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module logback.classic reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module logback.classic reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jcl.over.slf4j reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jcl.over.slf4j reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jul.to.slf4j reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jul.to.slf4j reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module log4j.over.slf4j reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module log4j.over.slf4j reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module commons.logging reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module commons.logging reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.core reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.core reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.el reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.el reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.websocket reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module tomcat.embed.websocket reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module validation.api reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module validation.api reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jboss.logging reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jboss.logging reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module classmate reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module classmate reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jackson.annotations reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jackson.annotations reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module jackson.core reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module jackson.core reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.aop reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.aop reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.beans reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.beans reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.expression reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.expression reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module logback.core reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module logback.core reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module slf4j.api reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module slf4j.api reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot.starter reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging
Error:java: module spring.boot reads package org.apache.commons.logging.impl from both jcl.over.slf4j and commons.logging
D:\project\Java9Gradle\src\main\java\module-info.java
Error:(1, 1) java: module Java9Gradle.main reads package org.apache.commons.logging from both jcl.over.slf4j and commons.logging

My dependencies file and the module-info.java file are very straight forward.

module Java9Gradle.main {
    requires spring.boot;
}


group 'Java9Gradle'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.9

repositories {
    mavenCentral()
}

dependencies {
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter
    compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: '1.5.3.RELEASE'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.3.RELEASE'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Can someone please help??

Thanks,

Amar

like image 738
Amar Dev Avatar asked Jun 09 '17 17:06

Amar Dev


People also ask

What are modules in Java 9?

It is a set of related Packages, Types (classes, abstract classes, interfaces etc) with Code & Data and Resources. Each Module contains only a set of related code and data to support Single Responsibility (Functionality) Principle (SRP). The main goal of Java 9 Module System is to support Modular Programming in Java.

Are module and package same in Java?

A module is a collection of related Java packages and associated resources with a descriptor file, which contains information about which packages/resources are exposed by this module, which packages are used by current module and some other information.

What is package and module in Java?

A package contains many classes (. java files) and is basically a folder in your Java projects. A module contains many packages (folders with . java files). A module is basically a single purpose library.


2 Answers

Excluding the transitive dependency made it work and adjusting the module-info.java too!!!

compile("org.springframework.boot:spring-boot-starter:1.5.3.RELEASE") {
        exclude group: 'commons-logging', module: 'commons-logging'
    }
    compile("org.springframework.boot:spring-boot-starter-web:1.5.3.RELEASE"){
        exclude group: 'commons-logging', module: 'commons-logging'
    }
like image 150
Amar Dev Avatar answered Oct 13 '22 21:10

Amar Dev


According to the Jigsaw specs

Non-interference — The Java compiler, virtual machine, and run-time system must ensure that modules that contain packages of the same name do not interfere with each other. If two distinct modules contain packages of the same name then, from the perspective of each module, all of the types and members in that package are defined only by that module. Code in that package in one module must not be able to access package-private types or members in that package in the other module.

This is referred to as split packages in the answer by @Andy here. The solution thereby is to unsplit these packages and make sure that the packages that are included from your modules jcl.over.slf4j and commons.logging are accessed via only one module.


You can analyze both dependencies spring-boot-starter:1.5.3.RELEASE and spring-boot-starter-web:1.5.3.RELEASE to make sure either of the two modules is included in your project.

like image 3
Naman Avatar answered Oct 13 '22 21:10

Naman