使用Gradle删除/删除文件与战争 [英] Delete/Remove file from war with Gradle

查看:1311
本文介绍了使用Gradle删除/删除文件与战争的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gradle构建一个Spring Boot应用程序,并且我希望将 application.properties 文件从战争中删除,因为这将从外部加载(这是运行在一个tomcat容器中,没有嵌入)。

I'm using gradle to build a Spring Boot application, and I would like to have the application.properties file removed from the war, because that will be loaded externally (this is running in a tomcat container, not embedded).

我浏览了一下StackOverflow和Gradle文档,试图弄清楚该怎么做,但我不知道我不知道哪个阶段需要绑定,如果在创建战争之前或之后排除文件。似乎也有多种处理文件的方式。

I've looked around StackOverflow and the Gradle docs to try to figure out what to do, but I don't know which phase to tie into, and if I exclude the file before or after the war is created. There also seem to be multiple ways of dealing with files.

我相信Maven使用 packagingExcludes 作为等价物。 / p>

I believe Maven uses packagingExcludes for the equivalent.

推荐答案

尽管我无法阻止文件被添加到战争中,但是我可以在战争后删除文件被创建 - 部分归功于这个问题的提示:是否有一种快速的方法可以从jar / war中删除文件,而不必提取jar并重新创建它?

Although I was not able to prevent a file from being added to the war, I was able to remove a file after the war was created - thanks in part to a tip from this question: Is there a quick way to delete a file from a Jar / war without having to extract the jar and recreate it?

在我的 build.gradle 文件中,我将 war 命令与 exec 命令,这样我就可以在war文件创建后运行一个命令。该命令将从战争中移除 application.properties 文件。这是任务扩展的样子:

In my build.gradle file I appended the war command with an exec command so that I could run a command after the war file had been created. The command will remove the application.properties file from the war. This is what the task extension looks like:

war << {
    exec {
        workingDir 'build/libs'
        commandLine 'zip', '-d', "${appName}-${appVersion}.war", 'WEB-INF/classes/application.properties'
    }
}

总之,它会改变工作目录移至gradle放置战争的位置,然后使用 zip 命令从战争中移除文件。

In short, it changes the working directory to the location that gradle places the war, and then uses the zip command to remove a file from the war.

这篇关于使用Gradle删除/删除文件与战争的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆