Change files before Building

Hello ,

Newbie to Gradle

I have a class library that is being built using different jdk versions (Basically 1.8 and 11) and Different versions of an application.

e.g ./gradlew build -Pparameterx="Software1" -Dorg.jdk.home="pathtojdk"
./gradlew build -Pparameterx="Software2" -Dorg.jdk.home="pathtojdk"

This was working until a new version of the software changed an API and hence one class has to be modified to take that change into account. It’s just one line change

Previous Versions

ClassA classa = new ClassA();

New Version

ClassANew classa = new ClassANew();

So my question is

If i want to keep building for all versions then i only have to change these two lines and then i will have jars available for all versions.

Basically what i want is keep two copies of the class (the one that has changed) and overwrite the old version with the new version and build.

Is this even possible? is this the right way?


This sounds like a good case for using @Lance’s Java Flavours Plugin. Your common code will stay in the same place, but you’ll create a “flavour” for the old and new versions, which will allow you to have a different version of the class in each one and a different version of the dependency.

1 Like