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)
相关推荐
王元_SmallA2 分钟前
服务器公网IP、私网IP、弹性IP是什么?区别与应
java·后端
葵续浅笑22 分钟前
LeetCode - 杨辉三角 / 二叉树的最大深度
java·数据结构·算法·leetcode
装不满的克莱因瓶31 分钟前
【Java架构师】各个微服务之间有哪些调用方式?
java·开发语言·微服务·架构·dubbo·restful·springcloud
N 年 后44 分钟前
cursor和传统idea的区别是什么?
java·人工智能·intellij-idea
CodeLongBear1 小时前
从Java后端到Python大模型:我的学习转型与规划
java·python·学习
Miraitowa_cheems1 小时前
LeetCode算法日记 - Day 94: 最长的斐波那契子序列的长度
java·数据结构·算法·leetcode·深度优先·动态规划
Zz_waiting.1 小时前
统一服务入口-Gateway
java·开发语言·gateway
ada7_1 小时前
LeetCode(python)——49.字母异位词分组
java·python·leetcode
DyLatte1 小时前
AI时代的工作和成长
java·后端·程序员
青春不流名2 小时前
nginx
java