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)
相关推荐
你三大爷22 分钟前
再探volatile原理
java
2301_7816686127 分钟前
Redis 面试
java·redis·面试
郑洁文29 分钟前
基于SpringBoot的天气预报系统的设计与实现
java·spring boot·后端·毕设
沃夫上校43 分钟前
MySQL 中文拼音排序问题
java·mysql
Dcs1 小时前
用 Python UTCP 直调 HTTP、CLI、MCP……
java
快乐肚皮1 小时前
fencing token机制
java·fencing token
叶落阁主2 小时前
Neovim 插件 i18n.nvim 介绍
java·vue.js·vim
渣哥2 小时前
让集合线程安全的几种靠谱方法
java
dylan_QAQ2 小时前
Java转Go全过程06-工程管理
java·后端·go
a587692 小时前
消息队列(MQ)初级入门:详解RabbitMQ与Kafka
java·分布式·microsoft·面试·kafka·rabbitmq