简体   繁体   中英

How do I define the source location for a file based dependency in gradle

I have a gradle build script that defines a file dependency.

dependencies {
    testCompile files('lib/test/wibble-1.0.jar')
}

I have a source jar for the library that I would like to add to the dependency so that with in eclipse I can navigate to the source. How do I add that information to the dependency?

Adding source Jars for artifacts not resolved from a Maven repository requires some scripting of eclipse.classpath (see EclipseClasspath in the Gradle Build Language Reference ). It could look like this:

import org.gradle.plugins.ide.eclipse.model.*

eclipse {
    classpath {
        file {
            whenMerged { Classpath classpath ->
                classpath.entries.each { ClasspathEntry entry ->
                    if (entry instanceof AbstractLibrary && entry.library.file == file("lib/test/wibble-1.0.jar")) {
                        entry.sourcePath = fileReferenceFactory.fromFile(file("lib/test/wibble-1.0-sources.jar"))
                    }
                }
            }
        }
    }
}

You could generalize this code to add all source Jars in the lib directory that adhere to some naming convention.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM