2015-09-26 26 views
1

我需要用gradle包裝Maven構建。 壞主意,對,明白了。但是,我有大量的使用gradle的代碼庫,還有一些仍然使用maven。 我有一套gradle工具可以完成我所有的分支,部署和很多很酷的工作。我也想利用這個爲我的Maven項目。如何將maven或任何其他構建系統與gradle進行封裝,以便依賴關係工作

我的最高等級任務是「deb」,因爲我正在構建debian軟件包。我的樣板基礎設施任務依賴於「deb」,因此無論每個項目如何實現它,它都可以工作,而不管基礎構建基礎結構,maven,make,ant等等。每個項目只需要定義一個「deb」任務,並使其依賴於構建輸出debian包所需的任何內容。這樣基礎設施gradle腳本不關心具體的項目實施。

我的主要問題是,如何生成gradle內的依賴關係,這樣我就不會不必要地構建。

回答

0

下面是我結束的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") 
+0

的-DskipTests是存在的,因爲這一具體項目,當時的gradle下運行他們失敗了。這是我仍然需要解決的一個問題,但並不妨礙它按原樣使用。 –