2013-07-24 66 views
0

我已經具備以下條件:如何在distZip中包含測試類?

task packageTests(type: Jar) { 
    from sourceSets.test.output 
} 
distZip { 
    into(jarFolderName) { 
     from '.' 
     include 'conf/**' 
    } 
    into(jarFolderName) { 
     from '.' 
     include 'bin/**' 
     fileMode = 0755 
    } 
    into(jarFolderName) { 
     from 'build' 
     include 'logs' 
    } 
} 

添加dependOn將創建試驗瓶,但我怎麼能那麼它包含在分配zip文件?

回答

1

第1步:創建測試的jar:

task testJar(type: Jar) { 
    classifier = 'tests' 
    from sourceSets.test.output 
} 

第2步:它distZip:

applicationDistribution.from(testJar) { 
    into "tests" 
} 
+0

謝謝!如果我將'from sourceSets.test.classes'更改爲'from sourceSets.test.output',那對我有用。 – morja

+0

你是否也知道如何創建一個distZip,其中還包含測試依賴項? – morja

+0

使用fat-jar插件並自定義fatJar任務(這是一個Zip任務)https://github.com/musketyr/gradle-fatjar-plugin – JBaruch

1
into(someFolder) { 
    from packageTests 
} 

PS:我會寫其他into就像這樣:

into("$jarFolderName/conf") { 
    from "conf" 
} 
    into("$jarFolderName/bin") { 
    from "bin" 
} 
... 
+0

謝謝你,我確實改變了你的建議。 – morja

相關問題