Open renatoathaydes opened 6 years ago
The stacktrace:
java.lang.IllegalAccessError: class example.JavaTest (in module simple.main) cannot access class org.hamcrest.CoreMatchers (in module hamcrest.core) because module simple.main does not read module hamcrest.core
at simple.main/example.JavaTest.test1(JavaTest.java:11)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at junit@4.12/org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at junit@4.12/org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at junit@4.12/org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at junit@4.12/org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at junit@4.12/org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at junit@4.12/org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at junit@4.12/org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at junit@4.12/org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at junit@4.12/org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at junit@4.12/org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at junit@4.12/org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at junit@4.12/org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at junit@4.12/org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:106)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.base/java.lang.Thread.run(Thread.java:844)
Hm... even using only JUnit, I get an error... are you sure this plugin supports running JUnit tests?
I can only run JUnit tests when I add this to the build file:
test {
doFirst {
jvmArgs += [
'--add-exports', "simple.main/example=junit",
]
}
}
Interestingly, I was able to run my original Hamcrest test with adding this:
test {
doFirst {
jvmArgs += [
'--add-exports', "simple.main/example=junit",
'--add-reads', "simple.main=hamcrest.core",
]
}
}
Maybe you could generate these --add-exports
and --add-reads
automatically?
I wrote this Java test:
As you probably know,
JUnit
depends on hamcrest (partial output ofgradle depend
):So this should work, I think.