gradlex-org / java-module-testing

Gradle plugin to turn JVM Test Suites into Blackbox or Whitebox Test Suite for Java Modules
Apache License 2.0
15 stars 5 forks source link

stacktrace #50

Closed xenoterracide closed 7 months ago

xenoterracide commented 8 months ago

everything is here https://github.com/xenoterracide/java-commons/pull/43/commits/82542fb1252cc2eceb19ec5212b8a6cf50f5ed2e

❯ ./gradlew test
Error occurred during initialization of boot layer
java.lang.module.FindException: Module org.jspecify not found, required by com.xenoterracide.tools.java
Error occurred during initialization of boot layer
java.lang.module.FindException: Module org.jspecify not found, required by com.xenoterracide.tools.java
Process 'Gradle Test Executor 103' finished with non-zero exit value 1
org.gradle.process.internal.ExecException: Process 'Gradle Test Executor 103' finished with non-zero exit value 1
        at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:431)
        at org.gradle.process.internal.worker.DefaultWorkerProcess.onProcessStop(DefaultWorkerProcess.java:145)
        at org.gradle.process.internal.worker.DefaultWorkerProcess.access$000(DefaultWorkerProcess.java:42)
        at org.gradle.process.internal.worker.DefaultWorkerProcess$1.executionFinished(DefaultWorkerProcess.java:98)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:43)
        at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:268)
        at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:170)
        at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:148)
        at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:37)
        at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
        at jdk.proxy1/jdk.proxy1.$Proxy116.executionFinished(Unknown Source)
        at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:221)
        at org.gradle.process.internal.DefaultExecHandle.finished(DefaultExecHandle.java:371)
        at org.gradle.process.internal.ExecHandleRunner.completed(ExecHandleRunner.java:134)
        at org.gradle.process.internal.ExecHandleRunner.lambda$run$2(ExecHandleRunner.java:97)
        at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:80)
        at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:95)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1583)
cpovirk commented 7 months ago

I wonder if this is related to the fact that we put JSpecify's module-info under the mrjar root:

$ jar -tf $HOME/.m2/repository/org/jspecify/jspecify/0.3.0/jspecify-0.3.0.jar | grep module-info
META-INF/versions/9/module-info.class

I would like to think that tools would support it in that location. But we could investigate moving it back. We could probably test that by building after tweaking this line, but I don't know enough Gradle offhand to be confident I could pull off that and especially a retest using the new jar in 5 minutes :)

jjohannes commented 7 months ago

@cpovirk what jspecify does is correct. Gradle finds the module-info.class in META-INF/version/*.

@xenoterracide The problem is an inconsistency between the dependencies declared in Gradle and the requires directives in module-info in your project. It says

requires org.jspecify;

...in the module-info.

But

compileOnlyApi(libs.jspecify)

...in the build.gradle.kts.

It should hence be requires static transitive org.jspecify; in the module-info. Right now the jspecify module is expected by Java at runtime (as there is no static) but it is not put on the runtime path due to the compileOnlyApi scope in Gradle.

Hint: You may checkout our java-module-dependencies plugin, which exists for the very reason to avoid such inconsistencies by removing the redundancy caused by having to declare dependency scopes in both Java and Gradle.

xenoterracide commented 7 months ago

Could it maybe throw a better error than this?

xenoterracide commented 7 months ago

so, after this, and much more playing... it's interesting, whitebox seems to explode if I don't use compileOnlyApi(libs.jspecify), compileOnly doesn't work. There's no difference though whether I use require static vs require transient static, with whitebox or blackbox testing. I refreshed myself on the difference.

https://github.com/xenoterracide/java-commons/pull/43/files#diff-91ff8cfe205eb3f8fd2070cc2b13b07f06c856bb2ea868089d0d29bc604205e8

> Task :tools:compileTestJava FAILED
error: module not found: org.jspecify
1 error

I mean, that error by itself makes sense, except I'm not requesting it..

as an asside I'm not actually certain whether a type annotation library like jspecify, or jetbrains annotations should be compileOnly or compileOnlyApi although I've noticed with non JPMS projects I often end up with compile time warnings from annotations that where types on properties that they have are missing (spring, it's always spring-*).