簡體   English   中英

如何在Gradle中為基於文件的依賴項定義源位置

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

我有一個gradle構建腳本,它定義了文件依賴性。

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

我有一個要添加到依賴項的庫的源jar,以便在eclipse中可以導航到源。 如何將該信息添加到依賴項?

為未從Maven存儲庫解析的工件添加源Jar時,需要對eclipse.classpath一些腳本編寫(請參閱Gradle Build Language Reference中的EclipseClasspath )。 它可能看起來像這樣:

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"))
                    }
                }
            }
        }
    }
}

您可以對此代碼進行一般化,以在lib目錄中添加所有遵循某些命名約定的源Jar。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM