mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
106 stars 77 forks source link

Setting generateEpisode to false does not work - schemagen error #96

Closed jesperdj closed 6 years ago

jesperdj commented 6 years ago

Plugin: jaxb2-maven-plugin version 2.3.1

When I add <generateEpisode>false</generateEpisode> to the configuration of the jaxb2-maven-plugin, then I get an error because the episode file is not found.

I don't want to generate an episode file, but in the Maven output I see that the plugin is specifying the -episode option to schemagen anyway.

Output of running mvn clean package:

[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building jaxb2-plugin-bug 1.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ jaxb2-plugin-bug --- [INFO] Deleting D:\Projects\jaxb2-plugin-bug\target [INFO] [INFO] --- jaxb2-maven-plugin:2.3.1:schemagen (default) @ jaxb2-plugin-bug --- [ERROR] Execution failed. [ERROR]

     java.io.FileOutputStream.open0(Native Method)
     java.io.FileOutputStream.open(FileOutputStream.java:270)
     java.io.FileOutputStream.<init>(FileOutputStream.java:213)
     java.io.FileOutputStream.<init>(FileOutputStream.java:101)
     com.sun.xml.txw2.output.StreamSerializer.<init>(StreamSerializer.java:92)
     com.sun.xml.txw2.output.ResultFactory.createSerializer(ResultFactory.java:75)
     com.sun.tools.jxc.api.impl.j2s.JAXBModelImpl.generateEpisodeFile(JAXBModelImpl.java:187)
     com.sun.tools.jxc.ap.SchemaGenerator.process(SchemaGenerator.java:141)
     com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
     com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
     com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
     com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
     com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
     com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
     com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
     com.sun.tools.javac.main.Main.compile(Main.java:523)
     com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
     com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
     com.sun.tools.jxc.SchemaGenerator$Runner.compile(SchemaGenerator.java:261)
     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     java.lang.reflect.Method.invoke(Method.java:498)
     com.sun.tools.jxc.SchemaGenerator.run(SchemaGenerator.java:166)
     org.codehaus.mojo.jaxb2.schemageneration.AbstractXsdGeneratorMojo.performExecution(AbstractXsdGeneratorMojo.java:372)
     org.codehaus.mojo.jaxb2.AbstractJaxbMojo.execute(AbstractJaxbMojo.java:257)
     org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
     org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
     org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
     org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
     org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
     org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
     org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
     org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
     org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
     org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
     org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
     org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
     org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
     org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     java.lang.reflect.Method.invoke(Method.java:498)
     org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
     org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
     org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
     org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.484 s [INFO] Finished at: 2017-11-11T10:41:09+01:00 [INFO] Final Memory: 17M/211M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:schemagen (default) on project jaxb2-plugin-bug: [ERROR] +=================== [SchemaGenerator Error ''] [ERROR] | [ERROR] | SchemaGen did not complete its operation correctly. [ERROR] | [ERROR] | To re-create the error (and get a proper error message), cd to: [ERROR] | D:\Projects\jaxb2-plugin-bug [ERROR] | ... and fire the following on a command line/in a shell: [ERROR] | [ERROR] | schemagen -encoding UTF-8 -d D:\Projects\jaxb2-plugin-bug\target\schemagen-work\compile_scope -classpath /D:/Projects/jaxb2-plugin-bug/src/main/java/ -episode D:\Projects\jaxb2-plugin-bug\target\classes\META-INF\sun-jaxb.episode src\main\java\com\jesperdj\jaxb\domain\Address.java src\main\java\com\jesperdj\jaxb\domain\Customer.java src\main\java\com\jesperdj\jaxb\domain\Item.java src\main\java\com\jesperdj\jaxb\domain\Loyalty.java src\main\java\com\jesperdj\jaxb\domain\PurchaseOrder.java src\main\java\com\jesperdj\jaxb\domain\package-info.java [ERROR] | [ERROR] | The following source files should be processed by schemagen: [ERROR] | 0: file:/D:/Projects/jaxb2-plugin-bug/src/main/java/com/jesperdj/jaxb/domain/Address.java [ERROR] | 1: file:/D:/Projects/jaxb2-plugin-bug/src/main/java/com/jesperdj/jaxb/domain/Customer.java [ERROR] | 2: file:/D:/Projects/jaxb2-plugin-bug/src/main/java/com/jesperdj/jaxb/domain/Item.java [ERROR] | 3: file:/D:/Projects/jaxb2-plugin-bug/src/main/java/com/jesperdj/jaxb/domain/Loyalty.java [ERROR] | 4: file:/D:/Projects/jaxb2-plugin-bug/src/main/java/com/jesperdj/jaxb/domain/PurchaseOrder.java [ERROR] | 5: file:/D:/Projects/jaxb2-plugin-bug/src/main/java/com/jesperdj/jaxb/domain/package-info.java [ERROR] | [ERROR] +=================== [End SchemaGenerator Error] [ERROR] : D:\Projects\jaxb2-plugin-bug\target\classes\META-INF\sun-jaxb.episode (The system cannot find the path specified) [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Example project to demonstrate the issue:

jaxb2-plugin-bug.zip

lennartj commented 6 years ago

It seems that the generation crashes when schemagen expects an episode file and there is none. Will investigate if schemagen actually works without an episode file (which I suspect it does) and find the effect on the plugin and the generated schema.

As a workaround, simply generate the episode file. The configuration setting for the plugin which works is found below.

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>schemagen</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <transformSchemas>
                        <transformSchema>
                            <uri>http://www.jesperdj.com/jaxb-demo</uri>
                            <toFile>purchaseOrder.xsd</toFile>
                        </transformSchema>
                    </transformSchemas>
                    <!-- generateEpisode>false</generateEpisode -->
                </configuration>
            </plugin>