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)
相关推荐
4311媒体网5 小时前
C语言操作符全解析 C语言操作符详解
java·c语言·jvm
淡忘_cx5 小时前
使用Jenkins自动化部署spring-java项目+宝塔重启项目命令(2.528.2版本)
java·自动化·jenkins
毕设源码-钟学长5 小时前
【开题答辩全过程】以 基于SSM的孤儿救助信息管理系统设计与实现为例,包含答辩的问题和答案
java
独自破碎E5 小时前
【曼哈顿距离】BISHI25 最大 FST 距离
java·开发语言
苏涵.5 小时前
Java三大集合:List、Set、Map
java·开发语言
存在的五月雨5 小时前
Spring Security认证流程
java·开发语言·mysql
树码小子5 小时前
综合练习:验证码案例(1)总体设计
java·开发语言·spring
一嘴一个橘子5 小时前
idea 执行 Maven 的 `clean`、`install`、`package` 等命令报错
java
Sylvia-girl5 小时前
线程通讯~
java
MSTcheng.5 小时前
【C++】C++异常
java·数据库·c++·异常