Gradle - Java 9 - spring-data-ja

Viewed 678

I try to build an already existing project with the JDK 9 and gradle.

I think I have a problem with the module loading.

Here is a sample of my gradle dependencies :

compile("org.springframework:spring-context:${spring_version}"){
    exclude group: 'commons-logging', module: 'commons-logging'
}
compile("org.springframework.data:spring-data-jpa:${spring_data_version}"){
    exclude group: 'commons-logging', module: 'commons-logging'
}

compile ("org.apache.commons:commons-dbcp2:${commons_dbcp2_version}"){
    exclude group: 'commons-logging', module: 'commons-logging'
}
compile ("org.hibernate:hibernate-entitymanager:${hibernate_version}"){
    exclude group: 'org.jboss.spec.javax.transaction'
}

compile ("org.hibernate:hibernate-java8:${hibernate_version}"){
    exclude group: 'org.jboss.spec.javax.transaction'
}

When I try to build, I get the following error when running the tests:

java.lang.NoClassDefFoundError: javax/transaction/SystemException

So one solution was to also include the following dependency :

compile "javax.transaction:jta:1.1"

And the build now exits with the module duplication error like this :

error: module flyway.core reads package javax.transaction.xa from both jta and java.sql
error: module hibernate.jpa reads package javax.transaction.xa from both jta and java.sql
error: module hibernate.entitymanager reads package javax.transaction.xa from both jta and java.sql

I also tried to include the option --add-modules java.se.ee , but it still does not work.

To resume my question : I need to have the java.sql in my module-info.java but I also need the javax.transaction:jta dependency jar and this jar conflicts with the java.sql module.

Any help will be appreciated !

1 Answers

The issues doesn't state that its not able to find the module/package. It reads the package from two (possibly automatic) modules. You can exclude it from either of it keeping the other which still provides you the functionality that you need.

So currently, you can fix this by including -

exclude group: 'javax.transaction.xa', module: 'moduleBringingThisPackage' 

where 'moduleBringingThisPackage' can be found by scanning the dependency hierarchy of your module.


Though I am not very good at gradle, but to find the moduleBringingThisPackage, you can use

gradle dependencies

to list out the dependencies that are brought by your top-level dependencies and further you can exclude the dependency that adds in the javax.transaction.xa to them.


Edit: With the updated question, I think there is a shorter version to it.

(1) When I try to build, I get the following error when running the tests:

java.lang.NoClassDefFoundError: javax/transaction/SystemException

(2) So one solution was to also include the following dependency :

compile "javax.transaction:jta:1.1"

Don't do the Step (2) from above and instead just add the

{ options.compilerArgs += ["--add-modules", "java.se.ee"] }

in your build.gradle file at this point of time

Related