Omit version in filename of dependency

I have to use a dependency sapjco3 in my project. The resolved jar contains the version number as usual, in my case it’s sapjco3-3.0.13.jar.
As such, this jar is also contained in Class-Path attribute of the manifest.

The problem is, that the name of the jar must be sapjco3.jar, which is checked at runtime: using the jar named sapjco3-3.0.13.jar leads to an exception at runtime.

My question:
how am I supposed to omit the version in the artifact’s filename - and finally have it included in the manifest class-path correctly, i.e. without the version number?

Any help greatly appreciated!

You could probably do something like

configurations {
   sapjco3 { transitive = false } 
dependencies {
   sapjco3 'foo:sapjco3:3.0.13' 
   compile files({tasks.renameSapjco3}) 
task renameSapjco3(type: Copy) {
   from configurations.sapjco3
   into "$buildDir/renameSapjco3" 
   rename('.*', 'sapjco3.jar') 

Hi Lance,
thanks for your reply - unfortunately it didn’t solve my problem:
compile files({tasks.renameSapjco3}) does not seem to be sufficient to provide the sapjco3.jar to compile (btw: I use implementation): the classes contained in the jar cannot be found, so compilation errors occur.

What is more, I do not fully understand your suggestion:

  • you define a configuration sapjco3
  • then add the dependency
  • then ‘pipe’ it’s deps through the copy-task to perform the renaming
  • to finally add the task’s “results” as deps for implementation

So the trick is this files of a task dep?

I don’t understand what the copy into a dir renameSapjco3 is good for :thinking:
And as I said: it does not seem to work, yet :slightly_frowning_face: Am I missing something? Any other suggestions?

Try adding the following task and executing it

task echoJars {
   inputs.files configurations.compile
   doLast {
      configurations.compile.files.each {
         println "$it"
  1. Is renameSapjco3 executed before echoJars?

  2. Is $buildDir/renameSapjco3/sapjco3.jar in the list of jars?

Hi Lance,
with your hints I’ve been able to figure it out:

listing the jars revealed that not the renamed jar sapjco3.jar has been added to the deps by files({tasks.renameSapjco3}), but only the folder name /$buildDir/renameSapjco3

So I changed the dep from

  • implementation files({tasks.renameSapjco3})
  • implementation files({tasks.renameSapjco3}).asFileTree

This - in combination with an outputs.upToDateWhen { false } in the renameSapjco3 task - finally turned out to be the solution :smile:

Thank you very much :raising_hand_man:t2:

outputs.upToDateWhen { false } in the renameSapjco3 task

Don’t do this, if the file is up to date then the task can be skipped

I’d probably keep it as implementation files({tasks.renameSapjco3}) and change the task to

task renameSapjco3 {
   ext.outputDir = "$buildDir/renameSapjco3"
   inputs.files configurations.sapjco3
   outputs.files fileTree(outputDir)
   doLast {
      copy {
         from configurations.sapjco3
         into outputDir
         rename('.*', 'sapjco3.jar') 

works just as well - and is a little more concise, perhaps.

And thanks for the hint with the up-to-date-check - it has not been necessary after all, of course :+1:

Thanks again for your help!

It’s a timing thing, I was worried that files({tasks.renameSapjco3}).asFileTree might force the resolution too early… or perhaps the task dependency might be lost (ultimately meaning that compileJava task would not depend on renameSapjco3)