bjornvester / xjc-gradle-plugin Goto Github PK
View Code? Open in Web Editor NEWA Gradle plugin for running the XJC binding compiler to generate JAXB Java source code from XSD schemas
License: MIT License
A Gradle plugin for running the XJC binding compiler to generate JAXB Java source code from XSD schemas
License: MIT License
While the xjc processing is quiet when the flag is set, the call to JCodeModel.build()
spits out the name of every generated file it builds to System.out
.
It would be preferred to be fully quiet.
Hi, i'm missing an option to specify the language code or locale to use when invoking XJC. The current behavior is that environment variable LANG decides which language is selected for generating the JavaDoc comments in the generated files. I would like to have this reproducible, so I'd like a way to define the language on my own.
You currently use
// Set encoding (work-around for https://github.com/gradle/gradle/issues/13843) forkOptions.environment("LANG", System.getenv("LANG") ?: "C.UTF-8")
which basically passes the LANG envionment variable down to the XJC worker. But unfortunately LANG is nothing you can control from within a gradle build script or the gradle.properties file. The environment variable can only be set outside of the gradle script, i.e. its value depends on the environment found when the script runs.
My suggestion is to provide a "language" or "locale" option in the XJCExtension that is honored in the forkOptions code above.
I'm using Gradle 8.5 by the way.
Kind regards
Henning
Would be nice if there is a way to configure settings per schema, as well as for a group of them.
Something along these lines:
xjc {
schemas {
firstSet {
defaultPackage = "tld.domain.first"
markGenerated = true
xsdDir = project.file("${project.rootDir}/assets/schemas/first/")
}
secondSet {
defaultPackage = "tld.domain.second"
markGenerated = true
xsdDir = project.file("${project.rootDir}/assets/schemas/second/")
}
}
}
In that way, it would be possible to use Different package names/identifiers for a given "set". I think that would be a key piece for this plugin.
My build.gradle is like this:
...
...
xjc {
xjcVersion.set("3.0.0")
xsdDir.set(layout.projectDirectory.dir("src/main/resources/xsd"))
defaultPackage.set("com.xx.xxx.xxxx.model")
}
$ ./gradlew xjc --info
_*** What went wrong:
Execution failed for task ':integration:lib:restvalidation:validationManager:xjc'.
A failure occurred while executing com.github.bjornvester.xjc.XjcWorker
jakarta.xml.bind.JAXBException: Implementation of Jakarta XML Binding-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]**_
I am using 1.5.1 version.
classpath group: 'gradle.plugin.com.github.bjornvester', name:'xjc-gradle-plugin', version: '1.5.1'
The reason I want to use 3.0.0 version as I want to generate classes with jakarta imports.
If I don't use xjcVersion, then i don't see any issue but it creates files with javax.xml.bind.* and it's not compatible with other part of the code.
Can you please suggest why is it failing and is there anything else I need to do?
Command: C:\Java\java-11-openjdk-11.0.11.9-1.windows.redhat.x86_64\bin\java.exe --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx3072m -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\xxxx.gradle\wrapper\dists\gradle-7.1-all\1esmmb218muptbc8q7pychb8t\gradle-7.1\lib\gradle-launcher-7.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.1
As it stands, the XjcPlugin defers adding the java and resource sourceSets until the XjcTask is actually created. This causes some serious problems when trying to use plugins that read and use those sourceSets.
A big example of this is the gradle kotlin plugin, which expects the sourceSets to be stably set when the compile tasks are called. There's no guarantee of this because the XjcTask will configure the sourceSet at some arbitrarily unknown time in the future. As a result, references from Kotlin code to the generated Java code will result in Unresolved reference
errors.
I expected this to work:
tasks.named("compileKotlin") {
dependsOn("xjc")
}
But it seems this still causes the sourceSet to be configured too late.
Along with weird race conditions, it's possible to have concurrent modification exceptions:
sourceSets.main {
java.srcDir(tasks.named<XjcTask>("xjc").map { it.outputJavaDir })
}
Will throw concurrent modification exceptions because the srcDir is set from both the sourceSets block and the deferred task creation.
A good solution here is to just configure the sourceSet in an afterEvaluate block (outside of the task body). Extensions are fully populated in an afterEvaluate block, and this block will always run before any task is executed or added as long as it's in Plugin.apply
.
For now, a simple workaround is just to eagerly create the xjc
task:
val xjc by tasks.getting {}
I tried to use this plugin on java 11, but I get exception:
* What went wrong:
Execution failed for task ':libs:ndk-em-app-mods:xjc'.
> A failure occurred while executing com.github.bjornvester.xjc.XjcWorker
> javax/xml/bind/JAXBException
* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':libs:ndk-em-app-mods:xjc'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:73)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:49)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
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: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.github.bjornvester.xjc.XjcWorker
at org.gradle.workers.internal.DefaultWorkerExecutor$WorkerExecution.waitForCompletion(DefaultWorkerExecutor.java:285)
at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:115)
at org.gradle.internal.work.DefaultAsyncWorkTracker.access$000(DefaultAsyncWorkTracker.java:34)
at org.gradle.internal.work.DefaultAsyncWorkTracker$2.run(DefaultAsyncWorkTracker.java:83)
at org.gradle.internal.Factories$1.create(Factories.java:25)
at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLocks(DefaultWorkerLeaseService.java:254)
at org.gradle.internal.work.DefaultWorkerLeaseService.withoutProjectLock(DefaultWorkerLeaseService.java:165)
at org.gradle.internal.work.DefaultWorkerLeaseService.withoutProjectLock(DefaultWorkerLeaseService.java:159)
at org.gradle.internal.work.StopShieldingWorkerLeaseService.withoutProjectLock(StopShieldingWorkerLeaseService.java:90)
at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:79)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$5.run(ExecuteActionsTaskExecuter.java:412)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:393)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:376)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:213)
at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$1(ExecuteStep.java:33)
at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:33)
at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:58)
at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:35)
at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:48)
at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:33)
at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:39)
at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:35)
at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:51)
at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:45)
at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:31)
at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:201)
at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:70)
at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:45)
at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49)
at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:43)
at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:32)
at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:96)
at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:89)
at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:54)
at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:38)
at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:77)
at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:90)
at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:48)
at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:120)
... 35 more
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo.getCustomizationContext(BindInfo.java:306)
at com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo.getCustomizationUnmarshaller(BindInfo.java:332)
at com.sun.tools.xjc.reader.xmlschema.bindinfo.AnnotationParserFactoryImpl$1.<init>(AnnotationParserFactoryImpl.java:55)
at com.sun.tools.xjc.reader.xmlschema.bindinfo.AnnotationParserFactoryImpl.create(AnnotationParserFactoryImpl.java:54)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.createAnnotationParser(NGCCRuntimeEx.java:371)
at com.sun.xml.xsom.impl.parser.state.annotation.action0(annotation.java:59)
at com.sun.xml.xsom.impl.parser.state.annotation.enterElement(annotation.java:84)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
at com.sun.xml.xsom.impl.parser.state.NGCCHandler.spawnChildFromEnterElement(NGCCHandler.java:84)
at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:287)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
at com.sun.xml.xsom.impl.parser.state.NGCCHandler.revertToParentFromEnterElement(NGCCHandler.java:121)
at com.sun.xml.xsom.impl.parser.state.foreignAttributes.enterElement(foreignAttributes.java:61)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
at com.sun.xml.xsom.impl.parser.state.NGCCHandler.spawnChildFromEnterElement(NGCCHandler.java:84)
at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:199)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:243)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:279)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:267)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:191)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:227)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.startElement(NGCCRuntime.java:233)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.util.SubtreeCutter.startElement(SubtreeCutter.java:78)
at com.sun.tools.xjc.reader.ExtensionBindingChecker.startElement(ExtensionBindingChecker.java:120)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker.startElement(IncorrectNamespaceURIChecker.java:98)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.startElement(CustomizationContextChecker.java:163)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.ModelLoader$SpeculationChecker.startElement(ModelLoader.java:414)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.internalizer.VersionChecker.startElement(VersionChecker.java:73)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:357)
at com.sun.xml.xsom.parser.JAXPParser.parse(JAXPParser.java:70)
at com.sun.tools.xjc.ModelLoader$2.parse(ModelLoader.java:438)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:210)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:351)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.importSchema(NGCCRuntimeEx.java:258)
at com.sun.xml.xsom.impl.parser.state.importDecl.action0(importDecl.java:56)
at com.sun.xml.xsom.impl.parser.state.importDecl.leaveElement(importDecl.java:167)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.endElement(NGCCRuntime.java:289)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.xjc.util.SubtreeCutter.endElement(SubtreeCutter.java:82)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.endElement(CustomizationContextChecker.java:169)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at java.xml/org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:357)
at com.sun.xml.xsom.parser.JAXPParser.parse(JAXPParser.java:70)
at com.sun.tools.xjc.ModelLoader$2.parse(ModelLoader.java:438)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:210)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:351)
at com.sun.xml.xsom.impl.parser.ParserContext.parse(ParserContext.java:98)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:141)
at com.sun.tools.xjc.ModelLoader.createXSOMSpeculative(ModelLoader.java:455)
at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:310)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:121)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:76)
at com.github.bjornvester.xjc.XjcWorker.run(XjcWorker.kt:27)
at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:39)
at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$WorkerCallable.call(IsolatedClassloaderWorkerFactory.java:165)
at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory.executeInWorkerClassLoader(IsolatedClassloaderWorkerFactory.java:93)
at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory.access$000(IsolatedClassloaderWorkerFactory.java:53)
at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$1$1.execute(IsolatedClassloaderWorkerFactory.java:72)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$1.execute(IsolatedClassloaderWorkerFactory.java:69)
at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:105)
at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:99)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
... 3 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
... 111 more
Is it possible to disable always running the task as part of process resources / compile Java?
I'm generating the classes from xsd to a dir in buildSrc and they are used by a custom plugin..
I'm also storing the generated classes in source control.
I don't want the classes to be generated if I build the project..
For a configuration like:
xjc {
xjcVersion.set "3.0.2"
useJakarta.set true
xsdDir.set file("src/main/resources/xsd")
outputJavaDir.set file("src/model/java")
groups {
register("Thing") {
includes.add "Thing.xsd"
defaultPackage.set "com.stuff.messages"
}
register("In") {
includes.add "In.xsd"
defaultPackage.set "com.stuff.messages.in"
}
}
}
I would expect the generates files to appear in src/model/java/com/stuff/messages
and src/model/java/com/stuff/messages/in
. However, instead they land under build/generated/sources/xjc-<group-name>
. Notably, they have the correct file structure inside that directory, including correct package
declarations set from defaultPackage
.
If I add outputJavaDir.set file("src/model/java")
to each group (without removing the one set outside groups
) , then all files get dumped in src/model/java/com/stuff/messages
(even ones that should be in the deeper in/
folder, and package
declarations are all set to com.stuff.messages
. Notably, the printed paths for each generated class are correct, and show the extended com/stuff/messages/in/Class.java
path.
If I further specify the actual package path in each group, like outputJavaDir.set file("src/model/java/com/stuff/messages/in")
for the in
group, then the same thing happens as before -- package declarations are still all com.stuff.messages
, but now all files are dumped in src/model/java/com/stuff/messages/com/stuff/messages
(note the repeated package structure).
The example here is a bit simplified, but I think the issues primarily come from the fact that the destination packages and/or folders are nested in each other, and so creation (and deletion) order matters -- for instance, if the In
group starts generating first, deleting src/model/java/com/stuff/messages/in
and then proceeding to start populating it (which I did see happen, some of the deeper packages would get their directories created, but then would end up being destroyed), but then com.stuff.messages
starts generating and deletes src/model/java/com/stuff/messages
, we'd run into a problem. What's weird is it does seem like all the types are generated in the final folder (although that may not be the case, it's hard to tell from what I'm running), which means something more complicated is going on.
I ended up just having them all generate in the correct structure under build
, and copying them to where I needed the source code to be.
The README section about which files to generate schemas for is outdated, i.e. it refers to the xsdFiles
. Instead, this should probably be migrated to the includes
property.
I'm using your plugin on a Windows machine.
I want the generated Java files to be UTF-8 encoded.
However, they turn out to be Windows-1252 (the default encoding on my machine).
I tried to force UTF-8 encoding via the options block. See the following example.
Unfortunately this isn't working.
How can I change the encoding?
xjc {
xjcVersion = "2.3.3"
outputJavaDir = file("$buildDir/generated/java")
outputResourcesDir = file("$buildDir/generated/resources")
xsdDir = file("src/xsd")
xsdFiles = fileTree(dir: xsdDir, include: ['*.xsd'])
options = [
'-encoding', 'UTF-8']
}
When I use the plugin to parse https://schemas.xmlsoap.org/soap/envelope/
I get the following error:
Caught fatal error exception from XJC
org.xml.sax.SAXParseException; systemId: http://schemas.xmlsoap.org/soap/envelope/; lineNumber: 1; columnNumber: 1; Premature end of file.
It was working before, anyone know what is going on here, or how to resolve the issue?
When generating Java classes from schema it would be very convenient for classes to be annotated with the @generated annotation, making it easier to exclude them from test coverage tools (as an example).
I use the plugin for creating JAXB classes for an Austrian standard (ÖNORM) which worked fine so far.
After upgrading the Java runtime from Java17 to Java21 I see a new issue popping up.
* What went wrong:
Execution failed for task ':jre'.
> Cannot cast object '[/at/oenorm/schema/a2063/_2009_06_01/AekKenndatenType.class]' with class 'java.util.ArrayList' to class 'java.lang.Void' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.lang.Void(String)
Attached the XSD set.
XSDs.zip
It is also interesting to see that it works fine with
gradle run
and fails for
gradle jpackage
As said, the only difference is the Java runtime used.
A simple test project can be found here: https://github.com/danielpeintner/Java11Test/tree/non-modular
Note: Using the Java21 and downgrading to 17 in my Gradle project solves the problem also!? Any ideas what is happening?
compileJava {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
Currently the default xjc task is created and its output is added to the main SourceSet
.
I have a project that only generates code for the test SourceSet
. Ideally I would like the ability to switch the source set of the generated code.
It seems like the main SourceSet
is being hard-coded to be added to here
JAXB/XJC generates String rather than JAXBElement<String>
. How to generate JAXBElement<String>
?
<xs:element name="aerodromePrevious" type="xs:string" minOccurs="0" maxOccurs="1" nillable="true" />
xjc { options = ["-extension", "-Xnamespace-prefix", "-Xdefault-value"] xsdDir.set(layout.projectDirectory.dir("schemas/core")) includes = ["Test.xsd"] bindingFiles.setFrom(layout.projectDirectory.dir("binding").asFileTree.matching { include("**/*.xjb") }) }
For reference, it would be nice to have release tags on the relevant commits.
If xjcVersion.set("2.3.3") (or 3.0.0) is omitted when using groups to define multiple schema generations, the gradle build fails mysteriously with:
java.lang.StackOverflowError
at org.gradle.api.internal.provider.AbstractProperty.getProducer(AbstractProperty.java:178)
at org.gradle.api.internal.provider.AbstractProperty.getProducer(AbstractProperty.java:178)
at org.gradle.api.internal.provider.AbstractProperty.getProducer(AbstractProperty.java:178)
(and so on...)
This should not be the case as the documentation says: "It has been tested with XJC version 2.3.3 and 3.0.0 (from Jakarta EE). Defaults to 2.3.3."
Example something like this:
groups {
markGenerated.set(true)
register("MyXJC") {
xsdDir.set(layout.projectDirectory.dir("src/main/resources/jaxb"))
defaultPackage.set("com.something.foobar")
xsdFiles = project.files(xsdDir.file("Something.xsd"))
outputJavaDir.set(layout.projectDirectory.dir("src/generated/java/xjc/"))
}
}
Tested with xjc-gradle-plugin 1.6.0.
As a personal anectode because of this I tried to create alternative way to configure multiple tasks which have independent xjc definitions but that failed as it seems that the last configuration of xjc was solely picked.
Currently there is no way to change the output episode file name from sun-jaxb.episode. This create issues when you try and include the output jobs in Android apps because the merger detects the conflict and can't resolve it. There should be a way to rename the episode.
Hi, I have inherited an old project and have been tasked with upgrading everything at once. It is kind of a nightmare and I don't know a whole lot about all this anyway. One of the upgrades is going from Ant to Gradle and from Java 8 to Java 15 and updating Jaxb to 3.0 as well.
Of all the gradle jaxb plugins I found, this one seemed the best so I went with it. Got everything generating pretty well but it is not quite the same as it used to be. So I was hoping maybe I could get some help on this.
The previous ant target to build looked like this:
<target name="gen-jaxb" depends="init,clean-gen-jaxb"
description="Generates Java classes from the XSD definitions">
<taskdef name="xjc" classname="com.sun.tools.xjc.XJC2Task">
<classpath>
<fileset id="xjc" dir="${deps.dir}/jaxb-xjc" includes="**/*.jar" />
</classpath>
<classpath path="${project.buildpath}" />
</taskdef>
<xjc destdir="${src}">
<binding file="bindings.xml"/>
<schema dir="schemas" includes="**/*.xsd" />
<arg value="-verbose"/>
<arg value="-npa"/>
<arg value="-extension"/>
<arg value="-Xinject-code"/>
<arg value="-Xfluent-api"/>
<arg value="-Xcommons-lang"/>
<arg value="-Xannotate"/>
</xjc>
</target>
I have translated that to this:
plugins {
id "com.github.bjornvester.xjc" version "1.5.0"
}
dependencies {
xjc "org.glassfish.jaxb:jaxb-runtime:3.0.0"
xjc "org.glassfish.jaxb:jaxb-xjc:3.0.0"
}
xjc {
xjcVersion.set("3.0.0")
xsdDir.set(file("schemas"))
outputJavaDir.set(file("src/main/xjc"))
options.add("-verbose")
options.add("-npa")
options.add("-extension")
options.add("-Xinject-code")
options.add("-Xfluent-api")
options.add("-Xcommons-lang")
options.add("-Xannotate")
}
The first error I've run into for the actual build is the lack of a fluent API. So I'm guessing that I am doing the args wrong in this gradle plugin. I read that options was for 3rd party plugins. So I wasn't sure this would just work anyway. But gave it a shot.
So I guess my question is. How would I translate the args from the ant target to this gradle plugin?
Is it even possible? Or are those only Jaxb 2 options? Or do I need an additional gradle plugin?
I've been working on this about 15 hours straight now so thought I'd stop trying things and ask. :D
Any help is greatly appreciated! :) Thank you.
Excution failed:
Execution failed for task ':xjc'.
> A failure occurred while executing com.github.bjornvester.xjc.XjcWorker
> java.lang.NullPointerException (no error message)
When compiling xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://unbroken-dome.org/gradle-xjc-plugin/samples/books"
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
jaxb:version="3.0"
targetNamespace="http://unbroken-dome.org/gradle-xjc-plugin/samples/books">
<xsd:annotation>
<xsd:appinfo>
<!-- <jaxb:globalBindings>-->
<jaxb:globalBindings optionalProperty="primitive">
<jaxb:serializable/>
</jaxb:globalBindings>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType name="bookType">
<xsd:attribute name="title" type="xsd:string"/>
<xsd:attribute name="author" type="xsd:string"/>
<xsd:attribute name="bestseller" type="xsd:boolean"/>
<xsd:attribute name="publicationYear" type="xsd:gYear"/>
</xsd:complexType>
<xsd:element name="book" type="tns:bookType"/>
<xsd:complexType name="booksType">
<xsd:sequence>
<xsd:element ref="tns:book"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="books" type="tns:booksType"/>
</xsd:schema>
build.gradle:
plugins {
id('java-library')
id('com.github.bjornvester.xjc') version '1.6.0'
}
repositories {
mavenCentral()
}
dependencies {
xjc "org.glassfish.jaxb:jaxb-runtime:3.0.2"
xjc 'org.glassfish.jaxb:jaxb-xjc:3.0.1'
xjc 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'
xjc 'jakarta.annotation:jakarta.annotation-api:2.0.0'
xjc 'jakarta.activation:jakarta.activation-api:2.0.1'
}
xjc {
xjcVersion.set("3.0.0")
xsdDir.set(layout.projectDirectory.dir("src/main/schema"))
}
bindingFiles property is always empty in https://github.com/bjornvester/xjc-gradle-plugin/blob/master/src/main/kotlin/com/github/bjornvester/xjc/XjcTask.kt
Example configuration:
xjc { xsdDir = file("${projectDir}/src/main/resources/") bindingFiles = files("${projectDir}/src/main/resources/my-bindings.xjb") }
I fixed this locally by setting the bindingFiles property again in fun doCodeGeneration()
:
bindingFiles = getXjcExtension().bindingFiles
Also changed class member bindingFiles from val to var for my test.
There is a new Gradle feature - configuration caching: https://docs.gradle.org/current/userguide/configuration_cache.html
This plugin is not compatible with it and fails if the caching feature is enabled.
The following error is printed:
* What went wrong:
Some problems were found with the configuration of task ':broker-model:xjc' (type 'XjcTask').
- Type 'com.github.bjornvester.xjc.XjcTask' property 'xjcBindConfiguration' doesn't have a configured value.
Reason: This property isn't marked as optional and no value has been configured.
Possible solutions:
1. Assign a value to 'xjcBindConfiguration'.
2. Mark property 'xjcBindConfiguration' as optional.
Please refer to https://docs.gradle.org/7.1/userguide/validation_problems.html#value_not_set for more details about this problem.
- Type 'com.github.bjornvester.xjc.XjcTask' property 'xjcConfiguration' doesn't have a configured value.
Reason: This property isn't marked as optional and no value has been configured.
Possible solutions:
1. Assign a value to 'xjcConfiguration'.
2. Mark property 'xjcConfiguration' as optional.
Please refer to https://docs.gradle.org/7.1/userguide/validation_problems.html#value_not_set for more details about this problem.
- Type 'com.github.bjornvester.xjc.XjcTask' property 'xjcPluginsConfiguration' doesn't have a configured value.
Reason: This property isn't marked as optional and no value has been configured.
Possible solutions:
1. Assign a value to 'xjcPluginsConfiguration'.
2. Mark property 'xjcPluginsConfiguration' as optional.
Please refer to https://docs.gradle.org/7.1/userguide/validation_problems.html#value_not_set for more details about this problem.
Is this compatible with android?
Hey,
I'm having trouble with release 1.8.1, because of inconsistent bindings when there is more than one xjc-task involved (which will be the case, when multiple groups are configured). I attached a minimal example-project:
Each group is supposed to generate a single class (A
and B
).
A
has an xsd:dateTime
-attribute, which is supposed to be handled via a custom-converter, which is specified in the bindings-file xsd-templates/a/bindings_a.xjb
.
B
has an xsd:duration
-attribute, which is supposed to be handled via another converter, which is specified in the bindings-file xsd-templates/b/bindings_b.xjb
.
This example compiles, because it's using the plugin at version 1.8.0. But if you change it to 1.8.1, and replace the lines
bindingFiles = project.files(xsdDir.file("bindings_a.xjb"))
with
bindingFiles.setFrom(project.files(xsdDir.file("bindings_a.xjb")))
,
(the same for the B
-task respectively)
it will fail.
If we're attempting to run ./gradlew xjcA xjcB --rerun-tasks --info
, we see the problem in the output:
> Task :xjcA
Caching disabled for task ':xjcA' because:
Build cache is disabled
Task ':xjcA' is not up-to-date because:
Executed with '--rerun-tasks'.
Watching 22 directories to track changes
Watching 21 directories to track changes
Loading XSD files [/home/mz/git/private/XjcTest/xsd-templates/a/A.xsd]
file or directory '/home/mz/git/private/XjcTest/build/xjc/extracted-bind-files', not found
Loading binding files: [/home/mz/git/private/XjcTest/xsd-templates/b/bindings_b.xjb]
> Task :xjcB
Caching disabled for task ':xjcB' because:
Build cache is disabled
Task ':xjcB' is not up-to-date because:
Executed with '--rerun-tasks'.
Watching 16 directories to track changes
Watching 15 directories to track changes
Loading XSD files [/home/mz/git/private/XjcTest/xsd-templates/b/B.xsd]
file or directory '/home/mz/git/private/XjcTest/build/xjc/extracted-bind-files', not found
Loading binding files: [/home/mz/git/private/XjcTest/xsd-templates/b/bindings_b.xjb]
Note, that the task xjcA now loads the binding-file /home/mz/git/private/XjcTest/xsd-templates/b/bindings_b.xjb
, which means that the code from Main.java
will lead to compile errors. Either a.setMyDateTime(OffsetDateTime.MAX);
or b.setMyDuration(Duration.ofSeconds(4));
will produce an error, because one of the task will have worked with mismatched binding-file.
I'm guessing, that replacing the FileCollection
with ConfigurableFileCollection
and making them final has something to do with the problem, but I'm not well versed in the intricacies of gradle. I would appreciate it, if you could have a look.
When trying to XJC the following XSD https://docs.oasis-open.org/ebxml-msg/ebms/v3.0/core/os/ebms-header-3_0-200704.xsd I get his error:
Caught fatal error exception from XJC
org.xml.sax.SAXParseException; systemId: http://www.w3.org/2001/xml.xsd; lineNumber: 1; columnNumber: 1; Premature end of file.
Premature end of file.
Opening the link http://www.w3.org/2001/xml.xsd takes me to https://www.w3.org/2001/xml.xsd, and changing the schema location resolves the error.
However it won't fully compile as I suspect some underlying XSDs use the same reference.
In short I suspect the package has problems handling http links that should be opened in https.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.