賞金明天到期。_ 此問題的答案有資格獲得 250聲望賞金。 Decent Dabbler正在從有信譽的來源尋找答案:
我想知道如何獲取rootProject.name屬性,或者更好的是,對物件的參考,或者更好的是,我在陳述句中包含的其他專案Settings的完整物件。ProjectincludeBuild
我正在使用includeBuild將我自己的庫中的模塊包含在settings.gradle:
rootProject.name = "MyApp"
include ':app'
includeBuild '/usr/local/library/Android/Event'
includeBuild '/usr/local/library/Android/Location'
includeBuild '/usr/local/library/Android/Widget'
我知道我可以在以后迭代這些:
gradle.includedBuilds.each{ includeBuild ->
println includeBuild.name
}
但是,列印:
Event
Location
Widget
有沒有一種簡單的方法來獲取rootProject.name我在每個單獨的庫專案settings.gradle檔案中定義的 s ?
我知道我可以執行以下操作來提供替代名稱:
includeBuild('/usr/local/library/Android/Event', {name = 'com.example.android.event'})
includeBuild('/usr/local/library/Android/Location', {name = 'com.example.android.location'})
includeBuild('/usr/local/library/Android/Widget', {name = 'com.example.android.widget'})
...但是當我已經將它們定義為rootProject.name它們各自的settings.gradle.
相反,我正在尋找類似于:
gradle.includedBuilds.each{ includeBuild ->
println includeBuild.rootProject.name
}
例如,我知道includeBuild.projectDir. 我可以以某種方式獲得settings.gradle對該目錄中檔案的(決議)參考嗎?
uj5u.com熱心網友回復:
我設法使用以下方法解決了它org.gradle.tooling.GradleConnector:
import org.gradle.tooling.GradleConnector
import org.gradle.tooling.ProjectConnection
import org.gradle.tooling.model.GradleProject
def getIncludedProjectNamesMap(Project project) {
def projectNamesMap = new HashMap<String, String>()
project.gradle.includedBuilds.each { includedBuild ->
ProjectConnection connection = GradleConnector.newConnector()
.forProjectDirectory(includedBuild.projectDir)
.connect()
GradleProject includedProject = connection.getModel(GradleProject.class);
def name = includedProject.getName();
connection.close();
projectNamesMap.put includedBuild.name, name;
}
return projectNamesMap
}
println getIncludedProjectNamesMap(project)
...列印:
{Event=com.example.android.event, Location=com.example.android.location, Widget=com.example.android.widget}
...但這似乎相當慢,可能是由于它需要建立的所有連接。它現在可以完成這項作業,但我仍在尋找替代方法(如果有的話)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/482601.html
上一篇:AndroidGradlePlugin7.2忽略AndroidApp構建程序中添加的proguard檔案
下一篇:將超過1個引數傳遞給monad
