下面是我結束的gradle任務。
它的要點是我需要提出一些規則來計算項目構建系統生成的輸入和輸出文件。在這個例子中,它很簡單,因爲java依賴* .java,* .xml和**/pom.xml,就是這樣。 我的輸出都是debian軟件包,所以需要* .deb filespec。 setNewVersion任務允許我將我的基本版本字符串保留在gradle.properties中。我使用gmaven插件將其讀入maven newVersion字符串中。 (見Maven2 property that indicates the parent directory)
def env = System.getenv() // get env to pass in to child build
def sourceBaseDir = "source" // Source dir for the wrapped project
// Set the maven newVersion using gradle.properties.
task setNewVersion(type:Exec) {
group = "build"
description = "(nim) Copy newVersion string into maven variable"
commandLine "bash", "-c", "sed -e \"s/version/newVersion/\" gradle.properties > source/build.properties"
}
// Build the maven targets
task mvnBuild(type:Exec, dependsOn: setNewVersion) {
group = "build"
description = "(nim) Build store with maven - TODO: uses -DskipTests because mvn build from gradle fails with junit running."
environment = System.getenv()
workingDir = sourceBaseDir
inputs.files fileTree(sourceBaseDir) {
include '**/src/**/*.java', '**/src/**/*.xml', '**/pom.xml'
}
outputs.files fileTree(sourceBaseDir) {
include '**/target/*.deb'
}
println "inputs=${inputs.getFiles() .getFiles()}"
println "outputs=${outputs.getFiles().getFiles()}"
commandLine "mvn", "-DskipTests", "package"
}
// Maven clean target
task mvnClean(type:Exec) {
group = "build"
description = "(nim) Clean store with maven, depends on local and remote repe cleanup as well"
workingDir = sourceBaseDir
commandLine "mvn", "clean"
}
task deb(dependsOn: "mvnBuild")
的-DskipTests是存在的,因爲這一具體項目,當時的gradle下運行他們失敗了。這是我仍然需要解決的一個問題,但並不妨礙它按原樣使用。 –