摇篮,复制和重命名文件

时间:2018-10-31 15:45:37

标签: gradle build.gradle

我试图在gradle脚本中,为spring app创建bootJar之后,将创建的jar复制并重命名为新名称(将在Dockerfile中使用)。我不知道如何重命名文件(我不想在输出文件的docker版本中使用该版本)。

Variable1 <- c(10,20,30,40,50)
Variable2 <- c("a", "b", "c", "d", "d")
Date <- c("31 october 2018", "30 october 2018", "28 october 2018", "28 october 2018", "27 october 2018")
df2 <- data.frame(Variable1, Variable2, Date)
df2

2 个答案:

答案 0 :(得分:1)

您可以使用预期名称直接生成jar,而不用在扩展名archiveName中使用bootJar属性来重命名它:

bootJar {
   archiveName "kcentral-app.jar" // <- this overrides the generated jar filename
   baseName = 'kcentral-app'
   version =  version
}

编辑 如果需要保留原始jar文件名(包含版本),则可以如下更新buildForDocker任务定义:

task buildForDocker(type: Copy){
    from bootJar
    into 'build/libs/docker'
    rename { String fileName ->
        // a simple way is to remove the "-$version" from the jar filename
        // but you can customize the filename replacement rule as you wish.
        fileName.replace("-$project.version", "")
    }
}

有关更多信息,请参见Gradle Copy Task DSL

答案 1 :(得分:0)

您还可以执行以下操作:

task copyLogConfDebug(type: Copy){
    group = 'local'
    description = 'copy logging conf at level debug to WEB-INF/classes'
    from "www/WEB-INF/conf/log4j2.debug.xml"
    into "www/WEB-INF/classes/"
    rename ('log4j2.debug.xml','log4j2.xml')