10

Our Gradle build have --add-modules=java.xml.bind,java.activation,java.xml.ws.annotation to options.compilerArgs in JavaCompile to build with JDK9/10. That works great right now, but these modules are deprecated.

I want to prepare for JDK11 where these modules might be removed.

I have tried adding javax.xml.bind:jaxb-api:2.3.0, com.sun.xml.bind:jaxb-impl:2.3.0 and com.sun.xml.bind:jaxb-core:2.3.0 to compile and runtime as well as classpath in buildscript, but I still get NoClassDefFoundError.

What am I missing?

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':my-client:compileGroovy'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyExecuter.java:66)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:97)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:596)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.NoClassDefFoundError: Unable to load class groovy.xml.jaxb.JaxbGroovyMethods due to missing dependency javax/xml/bind/Unmarshaller
        at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:175)
        at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:56)
        at org.gradle.api.internal.tasks.compile.GroovyCompilerFactory$DaemonSideCompiler.execute(GroovyCompilerFactory.java:74)
        at org.gradle.api.internal.tasks.compile.GroovyCompilerFactory$DaemonSideCompiler.execute(GroovyCompilerFactory.java:62)
        at org.gradle.api.internal.tasks.compile.daemon.AbstractDaemonCompiler$CompilerCallable.call(AbstractDaemonCompiler.java:88)
        at org.gradle.api.internal.tasks.compile.daemon.AbstractDaemonCompiler$CompilerCallable.call(AbstractDaemonCompiler.java:76)
        at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:42)
        at org.gradle.workers.internal.WorkerDaemonServer.execute(WorkerDaemonServer.java:46)
        at org.gradle.workers.internal.WorkerDaemonServer.execute(WorkerDaemonServer.java:30)
        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 org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:101)
        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 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)
        ... 3 more

The reported missing class isn't 100% identical for each build: it switches between complaining about javax/xml/bind/JAXBContext, javax/xml/bind/Unmarshaller and javax/xml/bind/Marshaller.

neu242
  • 15,796
  • 20
  • 79
  • 114
  • I cannot tell you how to properly fix your issue but I can propose a workaround: set your `JDK_JAVAC_OPTIONS` environment variable to `--add-modules java.xml.bind` – ZhekaKozlov May 31 '18 at 13:45
  • @ZhekaKozlov Using `--add-modules` works perfectly fine, but that doesn't work in jdk11. I want to replace the deprecated modules with library dependencies instead, but the `compileGroovy` task doesn't seem to find them on the classpath. – neu242 May 31 '18 at 14:03
  • 1
    @ZhekaKozlov `--add-modules java.xml.bind` shouldn't be required with JDK/11, right? Moreover, neu242, did you check http://openjdk.java.net/jeps/320? Would be good to see the `build.gradle` dependencies you are using. – Naman May 31 '18 at 14:19
  • 1
    @neu242 I know next to nothing about Gradle, so these are all guesses... I can think of up to three moving parts that might need these dependencies: (a) The Gradle process itself, (b) the process launched for compilation, (c) the sources that are being compiled. I would guess that (b) is the case here - are you sure you've added these JARs to (b)? I would run Gradle with full debug output and hope to find out where exactly these JARs show up. – Nicolai Parlog May 31 '18 at 14:21
  • @neu242 Just a guess: if you put JAXB jars to `gradle/lib`, will it work? – ZhekaKozlov May 31 '18 at 14:29
  • @ZhekaKozlov Nope, that didn't work :( – neu242 Jun 01 '18 at 08:44
  • @Nicolai I've added the dependencies to `dependencies { compile(...) }`, but that doesn't seem to cut it. – neu242 Jun 01 '18 at 08:46
  • 1
    @neu242 Did you run with full debug output? If you did that with Maven, it would show you the exact class paths that are used for each process. That would at least answer the question, whether the JARs end up in the right place. – Nicolai Parlog Jun 01 '18 at 12:52
  • I'm having the same problem, but with Groovy 2.5.0. I tried the `--add-modules` approach for all tasks with type `AbstractCompile`, but unfortunately that's not working either. I hope you found a solution – kousen Jun 29 '18 at 21:28
  • 1
    For those with enough points and like to work on groovy - please vote for re-opening the question. This is very special bug and was fixed in 2.5.1/2.5.2 to address. – Jayan Sep 19 '18 at 11:41

2 Answers2

1

OK, this solved itself, possibly due new newer Groovy (2.5.1) and Gradle (4.7) dependencies.

neu242
  • 15,796
  • 20
  • 79
  • 114
0

This line in build.gradle dependencies solved this exact problem to me:

    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
Arcones
  • 3,954
  • 4
  • 26
  • 46