mojohaus / jaxb2-maven-plugin

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

Compile Fails When Project is a Module #115

Open txtad opened 6 years ago

txtad commented 6 years ago

When a working project is compiled as a module during the parent build, the path to the schema files seems to be calculated incorrectly.

/root/path/to/child/src/main/xsd/Schema.xsd

becomes

/root/path/to/parent/root/path/to/child/src/main/xsd/Schema.xsd

And the build fails because the longer path is non-existent. This fails the same way whether using the default schema location or specifying the location using the element. The strange thing is that the error message is:

[ERROR] +=================== [XJC Error]
[ERROR] |
[ERROR] | 0: file:/root/path/to/child/src/main/xsd/schema.xsd
[ERROR] |
[ERROR] +=================== [End XJC Error]

But if one scrolls back through all the maven output, the underlying error is found:

org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'file:/root/path/to/parent/root/path/to/child/src/main/xsd/schema.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
txtad commented 6 years ago

It would probably be helpful if I point out I'm using version 2.4.

Here's the plugin section from the parent pom.xml

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>jaxb2-maven-plugin</artifactId>
      <version>2.4</version>
    </plugin>
  <plugins>
</build>

And from the child

<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <executions>
      <execution>
        <phase>generate-sources</phase>
        <id>xjc</id>
        <goals>
          <goal>xjc</goal>
        </goals>
        <configuration>                         
          <packageName>my.package</packageName>
          <target>2.2</target>
          <sources>
            <source>xsd/schema.xsd</source>
          </sources>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
lennartj commented 5 years ago

Could you create an integration test for this issue, and send as a PR?

funfried commented 5 years ago

I think we have the same issue as described by @txtad. The strange thing is that sometimes it compiles and sometimes it doesn't. We changed our configuration now from <source>src/main/resources/xsd/schema.xsd</source> to <source>${basedir}/src/main/resources/xsd/schema.xsd</source>

So far it seems to work but we didn't compile that configuration very often so far. So we'll see ... Hope it helps to solve the issue (BTW: We also use version 2.4 of JAXB2 Maven Plugin)

txtad commented 4 years ago

@lennartj I see you'd asked for some test data. Would you please tell me what you need? I see this problem still exists in 2.5.0.

txtad commented 4 years ago

@funfried I can't get the ${basedir} workaround to work for me with 2.5.0. The workaround that I'm using is to create a directory inside of my master directory that has symlinks to my XML projects at the bottom of a path that completes the long path the plugin is looking for.

I created /root/path/to/parent/root/path/to/symlinktochild inside of the master project base dir.

funfried commented 4 years ago

@txtad We switched to another plugin in the meantime:

<groupId>com.github.davidmoten</groupId>
<artifactId>jax-maven-plugin</artifactId>

Because we had also issues compiling with JDK 11, maybe that's also an option for you.

txtad commented 4 years ago

@funfried Thanks for the tip. I've got this working with my workaround for now, but I'll look at jax-maven-plugin.

tclimis commented 3 years ago

I just wanted to add that I'm having this problem with a build on Mac OS, but the same build on Windows works just fine.