stianh / gradle-jaxb-plugin

Gradle plugin for generating jaxb classes.
17 stars 11 forks source link

Make it possible to configure schemaDir #5

Closed mraccola closed 12 years ago

mraccola commented 12 years ago

Currently the schemaDir is hard coded to "src/${sourceSet.name}/jaxb". Request to allow the default to be changed via a plugin convention object.

I took a look at the source code and it seems the plugin does define a convention object but the name of the object, JaxbSourceDirectory, does not lend itself to extension. I would be happy to create a patch if you felt like it was OK to rename the convention object perhaps to JaxbPluginConvention?

Also, please consider changing the default from "src/${sourceSet.name}/jaxb" to "src/${sourceSet.name}/xsd". This might be more appropriate because there could be other uses for these schemas other than just JAXB code generation.

stigkj commented 12 years ago

I've been meaning to add a convention object, but time has not allowed it. Think it would be easy to add just to be able to change the schemaDir. Not sure how it would work with the dynamic nature of the source sets.

JaxbSourceDirectory is not a normal plugin convention as one is created for each source set. So it is more a convention object for each JAXB source drectory set. So a plugin convention would be a new object :-)

Good point about changing the default from jaxb to xsd. A little narrowminded of me. That, at least, is a very easy fix.

mraccola commented 12 years ago

I have been able to work around the issue by adding this code to my build:

project.convention.plugins.java.sourceSets.all { SourceSet sourceSet -> sourceSet.jaxb { srcDir 'src/main/xsd' } }

Maybe something like this be nice to have?

sourceSets { main { xsd { srcDir 'src/main/xsd' } } }

stigkj commented 12 years ago

I'm afraid your sourceSets.all thing only works when you only have schemas in the main source directory set. An example:

sourceSets {
    main {
        ...
    }
    customer1 {
        ...
    }
    customer2 {
        ...
    }
}

Here you have 3 source sets which normally has 3 schema source directory sets:

src/main/jaxb
src/customer1/jaxb
src/customer2/jaxb

If you had applied your sourceSets.all thing on such a project, you would only get 1 source directory (src/main/xsd) for all source sets, which was not your intention, I would guess.

But you can actually change the directory properly for multiple source sets with the current version of the plugin, just like what you have done in the second block, but with jaxb as the source directory set name instead of xsd:

sourceSets {
    main {
        jaxb { srcDir 'src/main/xsd' }
    }
    customer1 {
        jaxb { srcDir 'src/customer1/xsd' }
    }
    customer2 {
        jaxb { srcDir 'src/customer2/xsd' }
    }
}

So when this issue is closed, the previous code block will be the standard setup, that is, the directory for the schemas will be src/<source set name>/xsd

stigkj commented 12 years ago

Regarding your wish for this:

sourceSets {
    main {
        xsd { <some overrides> }
    }
}

I think this is better:

sourceSets {
    main {
        jaxb { <some overrides> }
    }
}

As it is a source directory set for the JAXB plugin, it is better to name it jaxb than xsd.

stigkj commented 12 years ago

Changing the default source directory to .../xsd is moved into its own issue.

Then the rest of this issue is solved by using the options available in source sets as shown in previous comments.