mojohaus / jaxb2-maven-plugin

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

Duplicate Class Error due to XJC double source Root #91

Closed JulienHoullier closed 6 years ago

JulienHoullier commented 7 years ago

Issue on version 2.3.1, no issue on version 2.2

This issue happens on our Jenkins CI plateform, The runner try to build project files which where on /var/jenkins/workspace/. The workspace directory is a link to a mounted directory shared by Runners /u/jenkins

On our pom.xml the xjc goals confiuration is :

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <configuration>
                    <outputDirectory>${project.build.directory}/generated/jaxb</outputDirectory>
                    <sources>
                        <source>${xsd.dir}</source>
                    </sources>
                    <packageName>com.test.xml</packageName>
                </configuration>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

where xsd.dir is set to:

src/main/resources/xsd

And with -X logs XJC trace:

[DEBUG] +=================== [13 XJC Arguments] [0]: -xmlschema [1]: -encoding [2]: UTF-8 [3]: -p [4]: com.test.xml [5]: -d [6]: /var/jenkins/workspace/project/target/generated/jaxb [7]: -classpath [8]: /var/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.3.3_autoinstall/conf/logging/ [9]: -extension [10]: -episode [11]: /u/jenkins/project/target/generated/jaxb/META-INF/sun-jaxb.episode [12]: project/src/main/resources/xsd/.xsd

+=================== [End 13 XJC Arguments] and on System Properties traces:

I suspect here that either ${project.build.directory} is not resolved properly, or relative src/main/resource/xsd is not resolved the same as ${basedir}/src/main/resources/xsd

Then on later compile phase trace with -X:

[DEBUG] Source roots: [DEBUG] /var/jenkins/workspace/project/src/main/java [DEBUG] /var/jenkins/workspace/project/target/generated/jaxb [DEBUG] /u/jenkins/project/target/generated/jaxb

The last two folder are in fact the same, which leads to compilation errors:

[ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /var/jenkins/workspace/project/target/generated/jaxb/com/test/xml/Class1Xml.java:[42,8] duplicate class: com.test.xml.Class1Xml.java ...

stklcode commented 6 years ago

Any updates on that?

I got the same issue on a Jenkins istance.

[DEBUG] Source directories: [/var/lib/jenkins/jobs/project/workspace/foo/bar/src/main/java /var/lib/jenkins/jobs/project/workspace/foo/bar/target/generated-sources/jaxb /my/mount/jenkins/jobs/projects/workspace/foo/bar/target/generated-sources/jaxb]

where /var/lib/jenkins is a symlink to /my/mount/jenkins. No output directory specified in the pom.xml.

Interesting point: the build runs fine when executing the mvn command manually in the same container (workspace not cleaned after failure).

Also runs fine when there is no symlink present, so I'd suspect the problem,

Did I miss any flag to prevent that issue or is this indeed a bug?

lennartj commented 6 years ago

It seems that the plugin does not handle symlinks properly here (i.e. regards the symlinked directory in the same way as a non-symlinked one).

Does the same issue persist in version 2.4?

stklcode commented 6 years ago

Does the same issue persist in version 2.4?

Apparently not :+1: Just compiled a minimal test example that fails using 2.3.1, but succeeds with 2.4. Thanks for that!

I guess it has been fixed with #56, right?

lennartj commented 6 years ago

Indeed.