javagradlevariants

Creating variants for programming APIs in Gradle


I am kinda new to gradle… I created a Java API (now a Gradle project which builds an jar) a long time ago which has some sensitive parts responsible for unencrypting company data as well as some non sensitive stuff. I have a new project that requires part of this API and naturally I don´t want to give away the whole API to other developers/contractors.

Ideally what I would like to do is create two variants, (lets say "Pro" and "Lite" for arguments sake - a simple product line approach I guess).

Is it possible to use gradle to build two different jars?
1. One which is the Pro full API 2. One which is the Lite API stripped of the relevant classes.

I see some mention of "flavours" on the net but seems all the hits are to do with Android development and properties.

The worse case scenario is that I create a new project containing just the needed code, but if I add new features/bug fixes to the API I wouldn't get the benefits of having them consolidated in a single project.

Another way could be to structure the existing project into different projects and have the security related stuff (both I/O and model) as a different jar.

Many thanks to anyone who can shed some light here...


Solution

  • A single Gradle project can produce any number of JARs. You could simply add another Jar task and give it a unique classifier to distinguish it from the "standard" library.

    task jarLite(type: Jar) {
        classifier = 'lite'
        exclude '**/SomeProprietaryCode.class'
        with jar
    }