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.