gradle-jaxb-plugin icon indicating copy to clipboard operation
gradle-jaxb-plugin copied to clipboard

Lots of little updates and a few features.

Open wdschei opened this issue 9 years ago • 14 comments

I would have normally split this into multiple PR's, but they were to interleaved and I wanted to get this back out.

  • Changed the required relativity to the project.dir to instead use the standard Gradle naming.
  • Added the ability to specify the specific XSD's that are actually compiled.
  • Set a default bindings value to all: **/*.xjb
  • Added support for setting the new accessExternalSchema system property in JSE 8.
  • Added support for automatically creating the output directory as is standard in Gradle.
  • Added support for setting the classpath argument of the XJC Ant task so that XJC plugins can be used.
  • Added support for Gradle's new parallel project execution.

There are two unit tests that are failing using Gradle v1.12 and I can't get the integration tests to run at all.

I have also started trying to compile this under Gradle v2.10 and that is going fairly well. We forked it over here, https://github.com/rackerlabs/gradle-jaxb-plugin, and just brought in the source from the gradle-xsd-wsdl-slurping library. Same thing over there with not being able to run the integration tests~~, but there is only one test failing over there out of all the combined unit tests~~. It is also a different test than what is failing under Gradle v1.12. So I don't know.

Thanks for the great start on this, updating it was definitely better than starting from scratch.

EDIT: The last failing unit test was fixed with wdschei/gradle-jaxb-plugin@227e2d5a21110790eadcac507d8c8a82d90f4e79. EDIT: There is also a simple parallel build test that uses the the Rackspace published artifacts here: https://github.com/wdschei/gradle-jaxb-plugin-test

wdschei avatar Feb 02 '16 01:02 wdschei

I like these changes :) Thanks!

ktsunoda avatar Apr 25 '16 23:04 ktsunoda

Hi, wondering what's the plan to merge this pull request and release a new version of the plugin? @wdschei do you've a sample build.gradle showing your changes?

asarkar avatar May 16 '16 19:05 asarkar

@abhijitsarkar,

I don't know if he is going to officially release a new version of this, but if you take a look at this you can use the forked version we published.

  • https://github.com/wdschei/gradle-jaxb-plugin-test/blob/master/build.gradle#L25-L37

wdschei avatar May 16 '16 19:05 wdschei

Thanks @wdschei. Did you publish to jcenter or maven central? And do you any examples for me to get started? I've an existing Maven config that uses a plugin to put annotation on generated classes.

<execution>
   <phase>generate-sources</phase>
   <id>common-codegen</id>
   <goals>
      <goal>run</goal>
   </goals>
   <configuration>
      <target>
         <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask" classpathref="maven.plugin.classpath" />
         <xjc extension="true" destdir="${project.build.sourceDirectory}" removeOldOutput="no" binding="${schema.dir}/common-binding.xml">
            <arg line="-Xannotate" />
            <arg line="-episode ${basedir}/src/main/resources/META-INF/sun-jaxb.episode" />
            <schema dir="${schema.dir}" includes="common.xsd" />
            <produces dir="${project.build.sourceDirectory}" includes="**/*" />
            <classpath>
               <fileset dir="${settings.localRepository}">
                  <include name="org/jvnet/annox/annox/${annox.version}/*.jar" />
                  <include name="org/jvnet/jaxb2_commons/jaxb2-basics-annotate/${jaxb2-basics-annotate.version}/*.jar" />
                  <include name="org/jvnet/jaxb2_commons/jaxb2-basics-ant/${jaxb2-basics-ant.version}/*.jar" />
                  <include name="org/jvnet/jaxb2_commons/jaxb2-basics-tools/${jaxb2-basics-tools.version}/*.jar" />
               </fileset>
            </classpath>
         </xjc>
      </target>
   </configuration>
</execution>

asarkar avatar May 16 '16 20:05 asarkar

@abhijitsarkar We haven't publish to jcenter or maven central yet, in hopes that this pull request would be accepted and then it would be published as merely a new release. Since it wasn't in a timely manner, we did publish to the public Rackspace repository. My little hello-world'ish project is located at:

  • https://github.com/wdschei/gradle-jaxb-plugin-test

The project I work on and what prompted this pull request can be found here:

  • https://github.com/rackerlabs/repose

Both are good examples, it just depends on how well versed in Gradle as to which one would be better for you.

That said, it is on our backlog to publish our changes to a more standard repository at some point if this pull request is not accepted by then.

wdschei avatar May 16 '16 21:05 wdschei

@wdschei thanks again. I'll look. I think I know gradle enough to understand build scripts, however, as you can see in the code snippet above, I'm using a JAXB plugin, so I'll have to find a way to feed that to the gradle plugin.

asarkar avatar May 16 '16 21:05 asarkar

EDIT: The Repose master branch has been migrated to Gradle and the links have been updated.

@abhijitsarkar I forgot to mention that the Repose master branch is still on Maven for a couple more weeks, but the branch below has been migrated to Gradle:

  • https://github.com/rackerlabs/repose/tree/8.0.0.0

Specifically, the build.gradle below uses a JAXB plugin to automatically provide default values and a Fluent API:

  • https://github.com/rackerlabs/repose/tree/8.0.0.0/repose-aggregator/components/filters/keystone-v2-filter/build.gradle

Notice the xjc dependencies and the args

  • https://github.com/rackerlabs/repose/tree/8.0.0.0/repose-aggregator/components/filters/keystone-v2-filter/build.gradle#L2-L3
  • https://github.com/rackerlabs/repose/tree/8.0.0.0/repose-aggregator/components/filters/keystone-v2-filter/build.gradle#L39

wdschei avatar May 16 '16 21:05 wdschei

I'm looking here for indication of what you said "support for setting the classpath argument of the XJC Ant task" and don't see any. I'll now start digging through source code, but if you may provide a helpful pointer, I'll appreciate that.

asarkar avatar May 16 '16 21:05 asarkar

It is not in that documentation yet, we just added the same capabilities to the XJC module as were already present for the JAXB module.

wdschei avatar May 16 '16 21:05 wdschei

Putting in another plug to get this PR accepted. I'm new to Gradle from the maven world, and would like to be able to use this plugin. Tracking down the error in the JaxbPlugin (the improperly calculated xjc.conventionMapping.generatedFilesDirectory) was highly instructional :-)

Thx.

shljad avatar Jun 06 '16 16:06 shljad

+1 I need support for accessExternalSchema

esetnik avatar Jul 07 '16 17:07 esetnik

EDIT: Since this PR was not accepted/merged, the Repose team did publish this to the Gradle Plugins repository:

  • https://plugins.gradle.org/plugin/org.openrepose.gradle.plugins.jaxb

@esetnik As mentioned previously, it is on my team's backlog to get this published to a more common repository. In the mean time though, you can always use the version we have published to our public repository:

  • https://maven.research.rackspacecloud.com/content/repositories/public/
  • org.openrepose:gradle-jaxb-plugin:2.0.2

Example projects are linked above too.

wdschei avatar Jul 08 '16 14:07 wdschei

I'm still not able to run xjc task with an XSD that contains external references with: <xs:import namespace=. Do you have a workaround? Thanks

iocampomx avatar Feb 04 '17 19:02 iocampomx

@nafiux Are you using the plugin from this repository or the one from the fork referenced in this PR? Since this PR was not accepted/merged, the Repose team did publish this to the Gradle Plugins repository:

  • https://plugins.gradle.org/plugin/org.openrepose.gradle.plugins.jaxb

wdschei avatar Feb 05 '17 23:02 wdschei