Build the source with two java versions (Java1.5,java1.8) and produce two jars (jar1.5,jar1.8)

I’m new to gradle and learned some basic stuff.
Need to build the same project with two java versions. Currently it is on jdk1.5 and moving to jdk1.8 but they need jdk1.5 build for some old applications.
Dependencies also different for the jdk1.5 and jdk1.8.

Could you please help me in this how to proceed ?