Docker cache gradle dependencies

后端 未结 4 1193
攒了一身酷
攒了一身酷 2020-12-12 22:41

I\'m trying to deploy our java web application to aws elastic beanstalk using docker, the idea is to be able to run the container locally for development and testing and eve

4条回答
  •  离开以前
    2020-12-12 23:00

    I

    Add resolveDependencies task in build.gradle:

    task resolveDependencies {
        doLast {
            project.rootProject.allprojects.each { subProject ->
                subProject.buildscript.configurations.each { configuration ->
                    configuration.resolve()
                }
                subProject.configurations.each { configuration ->
                    configuration.resolve()
                }
            }
        }
    }
    

    and update Dockerfile:

    ADD build.gradle /opt/app/
    WORKDIR /opt/app
    RUN gradle resolveDependencies
    
    ADD . .
    
    RUN gradle build -x test --parallel && \
        touch build/libs/api.jar
    

    II

    Bellow is what I do now:

    build.gradle

    ext {
        speed = project.hasProperty('speed') ? project.getProperty('speed') : false
        offlineCompile = new File("$buildDir/output/lib")
    }
    
    dependencies {
        if (speed) {
            compile fileTree(dir: offlineCompile, include: '*.jar')
        } else {
            // ...dependencies
        }
    }
    
    task downloadRepos(type: Copy) {
        from configurations.all
        into offlineCompile
    }
    

    Dockerfile

    ADD build.gradle /opt/app/
    WORKDIR /opt/app
    
    RUN gradle downloadRepos
    
    ADD . /opt/app
    RUN gradle build -Pspeed=true
    

提交回复
热议问题