這是本文件的舊版!


Pack Zip Hello World

因為公司人數越來越多,開始有人和我們搶會議室;為了節省我們時間,我開發了一個自動訂會議室的工具。以往我都是透過ant去包裝軟體,這次嘗試用gradle去包裝這個小工具。
我的專案結構如下:


我的目標如下:

  1. 包裝為zip。
  2. config與webdrivers直接複製到zip中。
  3. scripts中的內容複製到zip root。
  4. 將編譯出來的東西包為jar並連同相依項目放到libs中。

apply plugin: 'java-library'
 
compileJava {
    options.encoding = 'UTF-8'
}
 
repositories {
    jcenter()
}
 
dependencies {
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.53.0'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-server-standalone', version: '2.53.0'
 
    compile 'log4j:log4j:1.2.17'
    compile 'org.slf4j:slf4j-api:1.7+'
 
    testImplementation 'junit:junit:4.12'
}
 
task buildZip(type: Zip) {
    from processResources
    into('libs') {
        from configurations.runtimeClasspath
        from configurations.runtime.allArtifacts.files
    }
    into('config') {
    	from 'config'
    }
    into('') {
    	from 'scripts'
    }
    info('webdrivers') {
    	from 'webdrivers'
    }
}