I am using modularity.inferModulePath = true with Gradle 6.4 but I still can’t get it to compile without this:
java {
modularity.inferModulePath = true
tasks.withType(JavaCompile) {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}
}
And I can’t get the tests to run without this:
tasks.withType(Test).configureEach {
useJUnitPlatform()
// The following jvm args fix a runtime problem where some pre-java 9 modules are not being added to module path
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'ALL-MODULE-PATH', // to resolve all modules in the module path to be accessed by gradle test runner
'--add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED',
'--add-exports', 'org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
'--add-exports', 'org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
'--add-reads', "$moduleName=ALL-UNNAMED",
'--patch-module', "$moduleName=ALL-UNNAMED=" + files(sourceSets.test.java.outputDir).asPath,
]
classpath = files()
}
}
My full build.gradle is as follows:
allprojects {
apply plugin: 'java'
apply plugin: 'idea'
}
subprojects {
repositories {
mavenCentral()
jcenter()
}
plugins.withType(JavaPlugin).configureEach {
java {
modularity.inferModulePath = true
tasks.withType(JavaCompile) {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}
}
sourceSets {
integrationTest
}
configurations {
all {
//Stops java 9+ jdeps split package errors
exclude group: 'javax.servlet', module: 'javax.servlet-api'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
exclude group: 'com.vaadin.external.google', module: 'android-json'
}
integrationTestImplementation.extendsFrom implementation
integrationTestRuntimeOnly.extendsFrom runtimeOnly
}
dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mockito:mockito-junit-jupiter:3.3.3'
// testImplementation 'org.junit.jupiter:junit-jupiter:5.4.2'
integrationTestImplementation project(path)
integrationTestImplementation 'org.springframework.boot:spring-boot-starter-test'
integrationTestImplementation 'org.hamcrest:hamcrest-core:2.2'
integrationTestImplementation 'com.h2database:h2:1.4.178'
def integrationTestJarTask = tasks.register(sourceSets.integrationTest.jarTaskName, Jar) {
archiveClassifier = 'integration-tests'
from sourceSets.integrationTest.output
}
def integrationTestTask = tasks.register('integrationTest', Test) {
description = 'Runs integration tests.'
group = 'verification'
testClassesDirs = sourceSets.integrationTest.output.classesDirs
// Make sure we run the 'Jar' containing the tests (and not just the 'classes' folder) so that test resources are also part of the test module
classpath = configurations[sourceSets.integrationTest.runtimeClasspathConfigurationName] + files(integrationTestJarTask)
shouldRunAfter('test')
}
tasks.named('check') { dependsOn(integrationTestTask) }
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
// The following jvm args fix a runtime problem where some pre-java 9 modules are not being added to module path
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'ALL-MODULE-PATH', // to resolve all modules in the module path to be accessed by gradle test runner
'--add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED',
'--add-exports', 'org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
'--add-exports', 'org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
'--add-reads', "$moduleName=ALL-UNNAMED",
'--patch-module', "$moduleName=ALL-UNNAMED=" + files(sourceSets.test.java.outputDir).asPath,
]
classpath = files()
}
}
}
Any ideas? I am using SpringBoot version 2.2.4.RELEASE