1

Hi I currently have the problem that the "requires transitive" directive does not open the used module in my dependent module.

To get familiar with jigsaw I started to write a new application with spring and JDK 10. I got a module named "database" that uses spring.data.jpa module. Additionally I got a second module named "mvc" that requires the module "database".

Now in the module-info.java in module "database" I defined the spring module as follows:

requires transitive spring.data.jpa;

I would expect to have this module also available in my module "mvc" but I do not. Any suggestions what I am doing wrong?

module-info.java of module database

 module database {

    requires java.sql;
    requires java.persistence;
    requires liquibase.core;

    requires spring.beans;
    requires transitive spring.data.jpa;
    requires spring.jdbc;
    requires spring.tx;
    requires spring.orm;

    exports de.database.entities to mvc;
    exports de.database.repositories to mvc;
  }

module-info.java of module mvc

module mvc {

    requires database;

    requires spring.context;
    requires spring.beans;
    requires spring.boot;

    exports de.mvc to application;

}

and as I said spring.data.jpa cannot be accessed in module mvc. Also the require directive requires spring.data.jpa is not possible.

EDIT:

database -> build.gradle

dependencies {
    implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa')

    implementation group: 'org.hsqldb', name: 'hsqldb'
    implementation group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api'
    implementation(group: 'org.liquibase', name: 'liquibase-core')

    implementation group: 'javax.xml.bind', name: 'jaxb-api'

    testImplementation (group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2')
}

mvc -> build.gradle

dependencies {
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2'
    implementation (group: 'org.springframework.boot', name: 'spring-boot-starter') {
        force = true
        exclude group: 'ch.qos.logback', module: 'logback-classic'
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }

//    implementation group: 'org.springframework.data', name: 'spring-data-jpa'

    implementation project(":database")
}

The problem here is that if I leave the dependency spring-data-jpa uncommented in module mvc the compilation will fail. I need to explicitly enable it in build.gradle eventhough it should be present as transitive dependency by the database module.

my error then is

> Task :mvc:compileJava FAILED
error: module not found: spring.data.jpa
1 error

I try to modularize the database part. The database part uses spring-repositories. So I use the interface JpaRepository that is in the module spring.data.jpa like this:

@Repository
public interface DestinationDao
  extends JpaRepository<Destination, Long>, JpaSpecificationExecutor<Destination>
{

}

And now I want to use this bean in my module mvc. This should work in my opinion even if I do not define the dependency on spring-data-jpa explicitly in the module mvc.

Goldfish
  • 614
  • 1
  • 7
  • 19
  • Could you share the code involved in the problem and what exactly are you trying to achieve? – Naman Jun 16 '18 at 02:32
  • I want the following: module database has a dependency via gradle.build to spring-data-jpa. This module should now expose this library to module mvc. providing the sourcecode would be a little bit more of work. Even if it is just a test program it has become quiet big – Goldfish Jun 16 '18 at 11:13
  • Couldn't really figure out the line drawn between `opens` and `requires transitive` for your use case. Maybe the code could help. – Naman Jun 16 '18 at 12:27
  • "spring.data.jpa cannot be accessed in module mvc." --- I think you need to explain this a bit more. Can you paste in the compile time or run time error that you are seeing? – Alan Bateman Jun 18 '18 at 06:10
  • @Goldfish Please run Gradle for the _mvc_ module with `--debug` and look for a debug message "Compiler arguments:" - is the Spring Data JPA JAR on the module path? (I would guess not.) – Nicolai Parlog Jun 20 '18 at 09:25

1 Answers1

0

Your module declarations are correct and mvc should read spring.data.jpa.

I guess you're getting a compile error? I'm not a Gradle expert, so I might be wrong here, but I think Gradle has a mode where it only uses direct dependencies during compilation. If spring.data.jpa were not in mvc's dependency list (in Gradle), then that would explain the problem.

To figure that out, run Gradle with --debug and look for a debug message "Compiler arguments:".

If that's not the case, please share exactly when and what error you get.

Nicolai Parlog
  • 47,972
  • 24
  • 125
  • 255
  • As you already suspected I am getting a compile error. But only if I run the application with gradle. If I start it in IntelliJ as springboot configuration everything is fine. With my gradle startscript on the other hand I am getting '> Task :mvc:compileJava FAILED error: module not found: spring.data.jpa' – Goldfish Jun 18 '18 at 16:22
  • I'm pretty sure the dependency is not on the module path. I edited the answer with a tip how to find out. – Nicolai Parlog Jun 18 '18 at 21:26
  • I edited the question with some additional information. Hope this clarifies my problem. – Goldfish Jun 19 '18 at 20:46