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