Building jar library from same source with different package names

Hi all,

I have a groovy library that have to use in this (rather odd) way:

if (env.contains("prd")){
  new net.**mylib**.DoStuff().do()
} else if (env.contains("dev"){
  new net.**mylibDEV**.DoStuff().do()
}
else {
  throw new SomeException("No package available for env '${env}' ")
}

I would like to make a gradle build producing two jars. The source code, except from different package naming, is identival. I’d like to accomplish this “package renaming” within the gradle build, but I haven’t found the optimal way of doing so.

These are the option that I’ve come across.

  • Shadow Plugin. But this plugin only seems to have a mechanism for renaming the package names of the dependencies, not the resulting libraries.
  • groovy-android-gradle-plugin. But this plugin is dependent on the android sdk, which is not used by the library. Plus, it didn’t get along with the existing actions (doFirst etc) that was applied to task org.gradle.api.tasks.testing.Test
  • Writing a refactor taks in gradle.

Thanks,
G

Hi again,

I’m noticing that this post hasn’t got any responses in the last 6 days.

It’s my first time here at discuss.gradle so please let me know if there’s anything I could clarify.