Compiling packages within sourceSet with different java versions and source compatibility

We are looking at migrating our home-grown build tool to use gradle. Due to the nature of the various platforms our code base needs to support, a typical java project may need certain packages to be compiled with j2me instead of j2se. Also, various packages may required source compatibility of 1.3, while others can use 1.6.

For example:


(requires j2se and 1.6)


(requires j2me and 1.3) … etc.

What would be the best way build such a project using gradle? An important requirement is that the generated classfiles must all be in the same jar file; we don’t create different jars for different configurations.

Thanks for your help.

You can either model these as separate source sets, or declare multiple ‘Compile’ tasks. In either case, you’ll then have to directly (and separately) configure the ‘Compile’ tasks with the required settings (see the DSL reference for configuration options). Finally, you declare and/or configure a ‘Jar’ task that packages all the classes.