Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4004402
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:16:09+00:00 2026-05-20T08:16:09+00:00

I have a Maven project that uses the jaxb2-maven-plugin to compile some xsd files.

  • 0

I have a Maven project that uses the jaxb2-maven-plugin to compile some xsd files. It uses the staleFile to determine whether or not any of the referenced schemaFiles have been changed. Unfortunately, the xsd files in question use <xs:include schemaLocation="../relative/path.xsd"/> tags to include other schema files that are not listed in the schemaFile argument so the staleFile calculation in the plugin doesn’t accurately detect when things need to be actually recompiled. This winds up breaking incremental builds as the included schemas evolve.

Obviously, one solution would be to list all the recursively referenced files in the execution’s schemaFile. However, there are going to be cases where developers don’t do this and break the build. I’d like instead to automate the generation of this list in some way.

One approach that comes to mind would be to somehow parse the top-level XSD files and then either sets a property or outputs a file that I can then pass into the schemaFile parameter or schemaFiles parameter. The Groovy gmaven plugin seems like it might be a natural way to embed that functionality right into the POM. But I’m not familiar enough with Groovy to get started.

Can anyone provide some sample code? Or offer an alternative implementation/solution?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:16:09+00:00Added an answer on May 20, 2026 at 8:16 am

    Based on tim_yates’s answer, the following is a workable solution, which you may have to customize based on how you are configuring the jaxb2 plugin.

    Configure a gmaven-plugin execution early in the lifecycle (e.g., in the initialize phase) that runs with the following configuration…

    Start with a function to collect File objects of referenced schemas (this is a refinement of Tim’s answer):

    def findRefs { f ->
        def relPaths = new XmlSlurper().parse(f).depthFirst().findAll {
            it.name()=='include'
        }*.@schemaLocation*.text()
        relPaths.collect { new File(f.absoluteFile.parent + "/" + it).canonicalFile }
    }
    

    Wrap that in a function that iterates on the results until all children are found:

    def recursiveFindRefs = { schemaFiles ->
        def outputs = [] as Set
        def inputs  = schemaFiles as Queue
        // Breadth-first examine all refs in all schema files
        while (xsd = inputs.poll()) {
            outputs << xsd
            findRefs(xsd).each {
                if (!outputs.contains(it)) inputs.add(it)
            }
        }
        outputs
    }
    

    The real magic then comes in when you parse the Maven project to determine what to do.
    First, find the JAXB plugin:

    jaxb = project.build.plugins.find { it.artifactId == 'jaxb2-maven-plugin' }
    

    Then, parse each execution of that plugin (if you have multiple). The code assumes that each execution sets schemaDirectory, schemaFiles and staleFile (i.e., does not use the defaults!) and that you are not using schemaListFileName:

    jaxb.executions.each { ex ->
        log.info("Processing jaxb execution $ex")
        // Extract the schema locations; the configuration is an Xpp3Dom
        ex.configuration.children.each { conf ->
            switch (conf.name) {
                case "schemaDirectory":
                    schemaDirectory = conf.value
                    break
                case "schemaFiles":
                    schemaFiles = conf.value.split(/,\s*/)
                    break
                case "staleFile":
                    staleFile = conf.value
                    break
            }
        }
    

    Finally, we can open the schemaFiles, parse them using the functions we’ve defined earlier:

        def schemaHandles = schemaFiles.collect { new File("${project.basedir}/${schemaDirectory}", it) }
        def allSchemaHandles = recursiveFindRefs(schemaHandles)
    

    …and compare their last modified times against the stale file’s modification time,
    unlinking the stale file if necessary.

        def maxLastModified = allSchemaHandles.collect {
                it.lastModified()
            }.max()
        def staleHandle = new File(staleFile)
        if (staleHandle.lastModified() < maxLastModified) {
            log.info("  New schemas detected; unlinking $staleFile.")
            staleHandle.delete()
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a maven project that uses some custom jars [not found in any
We have a multi-module maven project that uses a profile that defines a buildnumber-maven-plugin
I have a big Maven project that uses the PMD plugin for code quality
I have a project that uses the maven-assembly-plugin to create source and binary tar
I have a maven project which uses wsgen to generate XSD files from the
I have a maven project that converts text files of a specific format to
I have a Spring project that uses Maven and has several profiles to allow
I have a big project that uses maven and I'm creating the project's jar.
I have a project that uses some Java and some Groovy, and it's all
I have a multi-module Maven project that uses Spring IoC, something like parent-proj -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.