jaxb2-maven-plugin
jaxb2-maven-plugin copied to clipboard
XjcMojo does not work when pom.relativePath is used for Parent Project reference
The XjcMojo (and perhaps others) calls relativize with the baseDir set to something like System.getProperty("user.dir") which appears to be the project from which the Maven invocation occurs (mvn clean install).
This does not work if the parent of a project is not in the base path of that project, for example:
- /xjcProject/pom.xml
- /xjcProject-parent/pom.xml <=== if mvn clean install is invoked here, it will build xjcProject and fail
as compared to a more standard Maven structure:
- /xjcProject-parent/xjcProject/pom.xml
- /xjcProject-parent/pom.xml <=== if mvn clean install is invoked here, everything works because xjcProject-parent is a prefix of xjcProject's path and will be properly stripped and relativized
I am hitting this problem, too.
This is a challenge whenever an aggregator POM is used, and where that aggregator pom is not hierarchically located "above" the pom.xml which includes the plugin.
The key is the specific current working directory from which "mvn
Steps:
-
unzip jaxb2-maven-plugin-error.zip
-
cd jaxb2-maven-plugin-error
-
mvn -f aggregator/pom.xml clean package
// works -
cd aggregator
-
mvn -f pom.xml clean package
--> failure triggered by jaxb2-maven-plugin, and reported by the plugin as
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'file:/home/myself/jaxb2-maven-plugin-error/aggregator/home/myself/jaxb2-maven-plugin-error/my-module/thing/my.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>.
while maven reports the error as
[ERROR] +=================== [XJC Error]
[ERROR] |
[ERROR] | 0: file:/home/myself/jaxb2-maven-plugin-error/my-module/thing/my.xsd
[ERROR] |
[ERROR] +=================== [End XJC Error]
Do note file:/home/myself/jaxb2-maven-plugin-error/my-module/thing/my.xsd
(which exists) vs file:/home/myself/jaxb2-maven-plugin-error/aggregator/home/myself/jaxb2-maven-plugin-error/my-module/thing/my.xsd
which does not exist. An in the latter case, note the assembled file string by the jaxb2-maven-plugin
file:
/home/myself/jaxb2-maven-plugin-error/aggregator
/home/myself/jaxb2-maven-plugin-error/my-module
/thing/my.xsd
so there was too much expansion. Note, also that ${project.basedir} is always correct in my-module; it's just that "some magic" is done inside the plugin that expands the current working directory.
Note that https://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.5.0/example_xjc_basic.html has
Note: The plugin currently requires that you run it from within the maven project directory, i.e. where the pom.xml file resides. If the project is part of a multi-module Maven build, Maven will take care of this for you.
Basically I read the note to say: "do not worry about multi-module", but, in fact, that's exactly where the problem is.
This is all with maven 3.6.3 (on Linux, JDK 8), and I suspect that, perhaps, jaxb2-maven-plugin uses the current working directory inappropriately.
Possible work-around:
When triggering builds through an aggregator pom, with a multi-module build, make sure to have the operating system current working above the module.
In the above example with the aggregator pom, invoke mvn -f aggregator/pom.xml clean package
instead of mvn -f pom.xml clean package
Is it possible that PR #168 addresses this, problem, too?
I ran into this today with Java 11 on Ubuntu 20.04 on a flat, multi-module project.
This is a repo that demonstrates the problem
https://github.com/bekwam/Maven-JAXB-2-Bug-Demo
In the above example with the aggregator pom, invoke
mvn -f aggregator/pom.xml clean package
instead ofmvn -f pom.xml clean package
This work for me...