Gradle build: Exclude resources files from Spring Boot Jar file

Ali n :

I would like to exclude all config files from the jar file since they will be provided at the provisioning and having a different version in the build path may create some runtime issues. I am using the following Gradle build script, but for some reason, I can still see whatever exist in the resources directory to be copied into the built Jar. Which means for some reason the provided Gradle build is not working as expected.

apply plugin: 'distribution'

    distributions {
        main {
            baseName = "${project.name}"
            contents {
                into('/conf'){
                    from('src/main/resources')
                    exclude("application.yml")
                }
                into('/lib'){
                    from('build/libs')
                }
                into('/bin'){
                    from('../bin')
                }
            }
        }
    }


    processResources {
        # Not sure how I need to point to the resources, so I included both. However, none is working.
        exclude('resources/*')
        exclude('src/main/resources/*')
    }

    bootJar{
        # Not sure how I need to point to the resources, so I included both. However, none is working.
        exclude('resources/*')
        exclude('src/main/resources/*')    
    }

    distTar {
        dependsOn bootJar
    }

    tasks.withType(Tar) {
        compression = Compression.GZIP
        extension = "tar.gz"
    }

    configurations {
        customArch
    }

    artifacts {
        customArch file(distTar.archivePath)
    }
Ali n :

I was able to exclude resources from appearing in the Jar file by using processResources.enabled = false, so the build file is as follows.

apply plugin: 'distribution'

distributions {
    main {
        baseName = "${project.name}"
        contents {
            into('/conf'){
                from('src/main/resources')
                exclude("application.yml")
            }
            into('/lib'){
                from('build/libs')
            }
            into('/bin'){
                from('../bin')
            }
        }
    }
}

processResources.enabled = false

distTar {
    dependsOn bootJar
}

tasks.withType(Tar) {
    compression = Compression.GZIP
    extension = "tar.gz"
}

configurations {
    customArch
}

artifacts {
    customArch file(distTar.archivePath)
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Build jar file but (dockerize) Spring Boot Application starts

Exclude application.properties inside spring boot jar using gradle

Spring Boot + Gradle: how to build executable jar

How to add static files to jar using Gradle build in Spring Boot + Angular 2 project

Gradle - Exclude file from being packaged with jar

resources in a Spring Boot application are missing from jar file when using Spring Boot Maven Plugin

How to exclude a jar from gradle

Gradle: Build 'fat jar' with Spring Boot Dependencies

How to exclude resources from the JAR in Gradle and also run via IntelliJ

Spring Boot Maven Plugin: Exclude properties file from final jar

Spring boot Gradle make a tar file from the built jar excluding resources

Spring boot reference file location from resources in properties file

How to exclude a jar from gradle

In an Android Gradle build, how to exclude dependencies from an included jar file?

How to exclude resource file from spring boot jar?

How to exclude file from resources using Gradle and Android Studio?

Exclude resources from dependency jar

Gradle artifactoryPublish won't deploy .jar file generated by spring boot

Why spring boot 1.5.3 jar does not recognise jsp files in src/main/resources/META-INF/resources/

Spring boot exclude properties file and provide it to jar on execution

How can I exclude files in Gradle's jar.from?

Spring Boot Issue between jar and task that build jar: Gradle

How to build DockerImage from Spring Boot jar

Spring boot, exclude dependencies from test in Gradle 5

Unable to read file from spring boot .jar

Updating spring boot static resources after deploying JAR file

Exclude class from jar with gradle

Understanding STS: Spring boot application works fine from STS but when gradle is used to build jar, the build fails

Exclude Test folder and Resources from Gradle Jar build

TOP Ranking

HotTag

Archive