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)
相关推荐
TFHoney1 小时前
Java面试第十一山!《SpringCloud框架》
java·spring cloud·面试
日暮南城故里2 小时前
Java学习------初识JVM体系结构
java·jvm·学习
鱼樱前端2 小时前
Java Jdbc相关知识点汇总
java·后端
canonical_entropy3 小时前
NopReport示例-动态Sheet和动态列
java·后端·excel
kkk哥3 小时前
基于springboot的母婴商城系统(018)
java·spring boot·后端
王者鳜錸3 小时前
四、小白学JAVA-石头剪刀布游戏
java·开发语言·游戏
坚持学习永不言弃4 小时前
【IDEA】 配置安装 Leetcode 插件
java·leetcode·intellij-idea
可乐加.糖6 小时前
Java 分布式高并发重试方案及实现
java·开发语言·spring boot·redis·分布式
沉默的煎蛋6 小时前
深入理解 TCP 三次握手与四次挥手
java·网络·数据结构·网络协议·tcp/ip