gradle/maven排除配置

maven


            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-jar-pluginartifactId>
                <configuration>
                    <excludes>
                        <exclude>application-gateway.ymlexclude>
                        <exclude>application.ymlexclude>
                        <exclude>logback-spring.xmlexclude>
                        <exclude>tag.propertiesexclude>
                    excludes>
                configuration>
            plugin>

以上配置则会排除掉main/resource下的文件

gradle

例如打包后的war/jar,排除掉src/main/resources下的config.properties

processResources {
    // 指定源目录为 src/main/resources
    from 'src/main/resources'

    // 排除 config.properties 文件
    exclude 'config.properties'

    // 设置输出目录为 build/resources/main
    into 'build/resources/main'
}

但是本地运行依然想使用

task copyConfigToLocal(type: Copy) {
    from 'src/main/resources'
    into 'build/resources/main'
    include 'config.properties'
}

完整示例:

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)

你可能感兴趣的:(SpringBoot,maven,java)