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)
相关推荐
jiayong2316 分钟前
Spring IOC 与 AOP 核心原理深度解析
java·spring·log4j
卿雪24 分钟前
Redis 线程模型:Redis为什么这么快?Redis为什么引入多线程?
java·数据库·redis·sql·mysql·缓存·golang
lkbhua莱克瓦2430 分钟前
IO流练习(修改文件中的数据)
java·windows·学习方法·io流·java练习题·io流练习
老华带你飞35 分钟前
汽车销售|汽车报价|基于Java汽车销售系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·后端·汽车
西岭千秋雪_1 小时前
MySQL集群搭建
java·数据库·分布式·mysql
小马爱打代码1 小时前
Spring AI:文生视频 - wanx2.1-i2v-plus
java·人工智能·spring
华仔啊1 小时前
RebbitMQ 入门教程看这一篇就够了
java·后端·rabbitmq
象象翔1 小时前
AI+若依(实战篇)
java·人工智能·spring boot·spring
CHANG_THE_WORLD1 小时前
C++ vs Python 参数传递方式对比
java·c++·python
talenteddriver1 小时前
java: 4种API 参数传递方式
java·开发语言