javamavenjaxb2-maven-plugin

Is it possible to override package path of Maven dependency?


In my Maven project i use jaxb2-maven-plugin which uses com.sun.xml.bind.external:rngom dependency. The problem is that from version 2.2.11 of rngom the package org.kohsuke.rngom was moved to com.sun.tools.rngom. I can no longer use 2.2.11 as dependency for vulnerability reasons.

If i am using a superrior version than 2.2.11 of com.sun.xml.bind.external:rngom i have build error, because the classes are no longer in package : org.kohsuke.rngom but in com.sun.tools.rngom.

Error :

Exception in thread "main" java.lang.Error:
  java.lang.reflect.InvocationTargetException at
  com.sun.tools.xjc.reader.Ring.get(Ring.java:113) at
  com.sun.tools.xjc.reader.xmlschema.BGMBuilder.(BGMBuilder.java:147) at
  com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:117)
  at
  com.sun.tools.xjc.ModelLoader.annotateXMLSchema(ModelLoader.java:407)
  at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:162) at
  com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:117) at
  com.sun.tools.xjc.Driver.run(Driver.java:354) at
  org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution(AbstractJavaGeneratorMojo.java:468)
  at
  org.codehaus.mojo.jaxb2.AbstractJaxbMojo.execute(AbstractJaxbMojo.java:315)
  at
  org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
  at
  org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
  at
  org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
  at
  org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
  at
  org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
  at
  org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
  at
  org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
  at
  org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
  at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305) at
  org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192) at
  org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105) at
  org.apache.maven.cli.MavenCli.execute(MavenCli.java:972) at
  org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293) at
  org.apache.maven.cli.MavenCli.main(MavenCli.java:196) at
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498) at
  org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
  at
  org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
  at
  org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
  at
  org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
  Caused by: java.lang.reflect.InvocationTargetException at
  sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at
  com.sun.tools.xjc.reader.Ring.get(Ring.java:102) ... 30 more Caused
  by: java.lang.Error: java.lang.reflect.InvocationTargetException at
  com.sun.tools.xjc.reader.Ring.get(Ring.java:113) at
  com.sun.tools.xjc.reader.xmlschema.BindGreen.(BindGreen.java:65) ...
  35 more Caused by: java.lang.reflect.InvocationTargetException at
  sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at
  com.sun.tools.xjc.reader.Ring.get(Ring.java:102) ... 36 more Caused
  by: java.lang.NoClassDefFoundError: org/kohsuke/rngom/nc/NameClass at
  com.sun.tools.xjc.reader.xmlschema.ct.ComplexTypeFieldBuilder.(ComplexTypeFieldBuilder.java:66)
  ... 41 more Caused by: java.lang.ClassNotFoundException:
  org.kohsuke.rngom.nc.NameClass at
  org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
  at
  org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
  at
  org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
  at
  org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
  ... 42 more

How could i fix this dependency problem ?


Solution

  • I have resolved the problem. I had to oupdate jaxb-xjc version from 2.3.0 to 2.3.2 and rngom to 2.3.3. It was confusing because jaxb-xjc dependency was never mentioned in build errors. You have to check minimal version requirement one by one in the dependency chain : plugin 2.5.0 has minimal requirement of jaxb-xjc v2.3.2 and jaxb-xjc has minimal requirement of rngom v2.3.2. Update all of the chain to minimal requirements.