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)
相关推荐
两个蝴蝶飞19 小时前
Java量化系列(四):实现自选股票维护功能
java·经验分享
短剑重铸之日20 小时前
7天读懂MySQL|Day 5:执行引擎与SQL优化
java·数据库·sql·mysql·架构
酒九鸠玖21 小时前
Java--多线程
java
Dreamboat-L21 小时前
云服务器上部署nginx
java·服务器·nginx
长安er21 小时前
LeetCode215/347/295 堆相关理论与题目
java·数据结构·算法·leetcode·
cici158741 天前
C#实现三菱PLC通信
java·网络·c#
k***92161 天前
【C++】继承和多态扩展学习
java·c++·学习
weixin_440730501 天前
java结构语句学习
java·开发语言·学习
JIngJaneIL1 天前
基于java+ vue医院管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
Coder_Boy_1 天前
Spring AI 源码大白话解析
java·人工智能·spring