Setting eclipse source (or javadoc) paths to unconventional names


(masterofwalri) #1

For reasons far beyond my control, I’m currently working with a convention for libraries that states that source jar names should follow the following convention: For ‘library.jar’, the source jar should be in the same directory, in ‘library.src.jar’.

Trying to get the ‘.classpath’ files generated by ‘gradle eclipse’ to point to these source jars has been a bit of a trial - they are picked up by gradle as being ivy dependencies, but are then just included as libs.

The best option I’ve been able to find is:

apply plugin: 'eclipse'
 eclipse {
  classpath {
     file {
    whenMerged { classpath ->
     fileFactory = new org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory()
     classpath.entries.removeAll { it.path.contains('.src') }
     classpath.entries.findAll { it.kind=='lib' }.each { it.sourcePath = fileFactory.fromPath(it.path.replace(".jar", ".src.jar")) }
    }
   }
  }
 }

Should this be achievable by declaring a ‘compile’ or ‘testCompile’ dependency properly?


(Peter Niederwieser) #2

Automatic configuration of source Jars in ‘.classpath’ currently only works if the source Jar follows the Maven naming convention. Hence I’d stick to manipulating the ‘.classpath’ file.


(Peter Niederwieser) #3

Automatic configuration of source Jars in ‘.classpath’ currently only works for source Jars following the Maven naming convention. Hence I’d stick to manipulating the ‘.classpath’ file.