我需要用gradle包装一个Maven构建。
坏主意,对,明白了。但是,我已经有很多使用gradle的代码库,还有一些仍然使用maven。
我有一组gradle工具,可以完成所有分支,部署和许多有趣的工作。我也想将其用于我的Maven项目。
在构建debian软件包时,我的首要任务是“deb”。我的样板基础结构任务依赖于“deb”,因此无论每个项目如何实现,它都可以工作,而与基础构建基础结构,maven,make,ant等无关。每个项目只需要定义一个“deb”任务,并使它依赖于构建输出debian软件包所需的一切。这样,基础架构gradle脚本就不必关心特定的项目实现。
我的主要问题是,如何在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")
关于maven - 我如何使用gradle包装Maven或任何其他构建系统,以便依赖项起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32802322/