gradle/maven排除配置

maven

xml 复制代码
<!--打包去掉jar包内的配置文件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>application-gateway.yml</exclude>
                        <exclude>application.yml</exclude>
                        <exclude>logback-spring.xml</exclude>
                        <exclude>tag.properties</exclude>
                    </excludes>
                </configuration>
            </plugin>

以上配置则会排除掉main/resource下的文件

gradle

例如打包后的war/jar,排除掉src/main/resources下的config.properties

json 复制代码
processResources {
    // 指定源目录为 src/main/resources
    from 'src/main/resources'

    // 排除 config.properties 文件
    exclude 'config.properties'

    // 设置输出目录为 build/resources/main
    into 'build/resources/main'
}

但是本地运行依然想使用

json 复制代码
task copyConfigToLocal(type: Copy) {
    from 'src/main/resources'
    into 'build/resources/main'
    include 'config.properties'
}

完整示例:

json 复制代码
plugins {
    id 'java'
}

repositories {
    mavenCentral()
}

dependencies {
    // 添加你的项目依赖
}

task copyConfigToLocal(type: Copy) {
    from 'src/main/resources'
    into 'build/resources/main'
    include 'config.properties'
}

processResources {
    from 'src/main/resources'
    exclude 'config.properties'
    into 'build/resources/main'
}

assemble.dependsOn(copyConfigToLocal)
相关推荐
代码AI弗森4 小时前
一文理清楚“算力申请 / 成本测算 / 并发评估”
java·服务器·数据库
Old Uncle Tom4 小时前
OpenClaw 记忆系统 -- 记忆预加载
java·数据结构·算法·agent
小小小米粒4 小时前
Collection单列集合、Map(Key - Value)双列集合,多继承实现。
java·开发语言·windows
摇滚侠5 小时前
expdp 查看帮助
java·数据库·oracle
:1215 小时前
java基础
java·开发语言
曹牧6 小时前
Spring:@RequestMapping注解,匹配的顺序与上下文无关
java·后端·spring
daixin88486 小时前
cursor无法正常使用gpt5.5等模型解决方案
java·redis·cursor
韦禾水7 小时前
记录一次项目部署到tomcat的异常
java·tomcat
曦月合一7 小时前
树莓派安装jdk、tomcat、vnc、谷歌浏览器开机自启等环境配置
java·tomcat·树莓派
此剑之势丶愈斩愈烈7 小时前
openssl 自建证书
java