W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
在 Gradle 中有一些對象的某些屬性可以接收一組輸入文件.例如,JavaComplile 任務(wù)有一個 source 屬性,它定義了編譯的源文件,你可以設(shè)置這個屬性的值,只要 files() 方法支持. 這意味著你可以使用 File ,String , collection , FileCollection 甚至是使用一個閉合去設(shè)置屬性的值.
例 15.8 指定文件
build.gradle
//使用一個 File 對象設(shè)置源目錄
compile {
source = file('src/main/java')
}
//使用一個字符路徑設(shè)置源目錄
compile {
source = 'src/main/java'
}
// 使用一個集合設(shè)置多個源目錄
compile {
source = ['src/main/java', '../shared/java']
}
// 使用 FileCollection 或者 FileTree 設(shè)置源目錄
compile {
source = fileTree(dir: 'src/main/java').matching { include 'org/gradle/api/**' }
}
// 使用一個閉合設(shè)置源目錄
compile {
source = {
// Use the contents of each zip file in the src dir
file('src').listFiles().findAll {it.name.endsWith('.zip')}.collect { zipTree(it) }
}
}
Usually, there is a method with the same name as the property, which appends to the set of files. Again, this method accepts any of the types supported by the files() method.
通常情況下,會有一個方法名和屬性名相同的方法能夠附加一組文件,這個方法接收 files() 方法支持的任何類型的值.
例 15.9 指定文件
build.gradle
compile {
// 使用字符路徑添加源目錄
source 'src/main/java', 'src/main/groovy'
// 使用 File 對象添加源目錄
source file('../shared/java')
// 使用閉合添加源目錄
source { file('src/test/').listFiles() }
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: