Gradle downloads maven metadata every build

Hi

On my cuba 7.2 project, each time I build gradle downloads maven-metadata which slows things down.

I found some solutions for a maven project to sort out the issue (e.g change the “updatePolicy”), but nothing for gradle.

Hereunder my build.gradle script in case I missed something obvious. Any help appreciated.

Regards
Michael

buildscript {
    ext.cubaVersion = '7.2.10'
    repositories {
        mavenCentral()
        maven {
            url 'https://repo.cuba-platform.com/content/groups/work'
            credentials {
                username(rootProject.hasProperty('repoUser') ? rootProject['repoUser'] : 'cuba')
                password(rootProject.hasProperty('repoPass') ? rootProject['repoPass'] : 'cuba123')
            }
        }

        maven {
            url 'https://repo.cuba-platform.com/content/groups/premium'
            credentials {
                username(rootProject.hasProperty('premiumRepoUser') ?
                        rootProject['premiumRepoUser'] : System.getenv('CUBA_PREMIUM_USER'))
                password(rootProject.hasProperty('premiumRepoPass') ?
                        rootProject['premiumRepoPass'] : System.getenv('CUBA_PREMIUM_PASSWORD'))
            }
        }

        maven { url 'http://repo.e-iceblue.com/nexus/content/groups/public/' }
    }
    dependencies {
        classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"
    }
}

def modulePrefix = 'ibusy2'

def globalModule = project(":${modulePrefix}-global")
def coreModule = project(":${modulePrefix}-core")
def webModule = project(":${modulePrefix}-web")
def webToolkitModule = project(":${modulePrefix}-web-toolkit")

def servletApi = 'javax.servlet:javax.servlet-api:3.1.0'

apply(plugin: 'cuba')

cuba {
    artifact {
        group = 'com.ibusy2'
        version = '0.1'
        isSnapshot = true
    }
}

dependencies {
    appComponent("com.haulmont.cuba:cuba-global:$cubaVersion")
    appComponent('com.haulmont.addon.dashboard:dashboard-global:3.2.3')
    appComponent('com.haulmont.charts:charts-global:7.2.10')
    appComponent("com.haulmont.reports:reports-global:$cubaVersion")
    appComponent('com.haulmont.addon.imap:imap-global:1.5.1')
    appComponent('com.haulmont.addon.helium:helium-global:0.3.1')
    appComponent('com.haulmont.addon.dnd:cuba-dnd-global:1.7.0')
    appComponent('com.haulmont.addon.bproc:bproc-global:1.2.0')
    appComponent('com.haulmont.addon.globalevents:cubaglevt-global:0.6.1')
    appComponent('com.haulmont.addon.emailtemplates:yet-global:1.4.2')
    appComponent('com.haulmont.addon.restapi:restapi-global:7.2.3')
    appComponent("com.haulmont.fts:fts-global:$cubaVersion")
    appComponent('br.com.petersonbr.translations:cuba-translations-addon-global:7.2.2')
}

def postgres = 'org.postgresql:postgresql:42.2.9'


configure([globalModule, coreModule, webModule, webToolkitModule]) {
    apply(plugin: 'java')
    apply(plugin: 'maven')
    apply(plugin: 'cuba')

    sourceCompatibility = '11'
    targetCompatibility = '11'

    dependencies {
        testCompile('org.junit.jupiter:junit-jupiter-api:5.5.2')
        testCompile('org.junit.jupiter:junit-jupiter-engine:5.5.2')
        testCompile('org.junit.vintage:junit-vintage-engine:5.5.2')
    }

    task sourceJar(type: Jar) {
        from file('src')
        classifier = 'sources'
    }

    artifacts {
        archives sourceJar
    }
    test {
        useJUnitPlatform()
    }
}


configure(globalModule) {
    dependencies {
        if (!JavaVersion.current().isJava8()) {
            compile('javax.xml.bind:jaxb-api:2.3.1')
            compile('org.glassfish.jaxb:jaxb-runtime:2.3.1')
        }
        compile('org.jetbrains:annotations:20.1.0')
        compile('org.apache.commons:commons-csv:1.4')
    }

    entitiesEnhancing {
        main {
            enabled = true
        }
    }
}

configure(coreModule) {

    configurations {
        jdbc
        dbscripts
    }

    dependencies {
        compile(globalModule)
        compile('net.sf.jasperreports:jasperreports:6.16.0')
        compileOnly(servletApi)
        jdbc(postgres)
        testRuntime(postgres)
        compile('e-iceblue:spire.xls.free:2.2.0')
    }

    task cleanConf(description: 'Cleans up conf directory', type: Delete) {
        delete "$cuba.appHome/${modulePrefix}-core/conf"
    }

    task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) {
        appName = "${modulePrefix}-core"
        appJars(modulePrefix + '-global', modulePrefix + '-core')
    }

    task createDb(dependsOn: assembleDbScripts, description: 'Creates local database', type: CubaDbCreation) {
    }
    task createTestDb(dependsOn: assembleDbScripts, type: CubaDbCreation) {
        dbms = 'postgres'
        host = 'localhost'
        dbName = 'ibusy2_test'
        dbUser = 'cuba'
        dbPassword = 'cuba'
    }
    task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) {
    }
    task updateTestDb(dependsOn: assembleDbScripts, description: 'Updates test database', type: CubaDbUpdate) {
        dbms = 'postgres'
        host = 'localhost'
        dbName = 'ibusy2_test'
        dbUser = 'cuba'
        dbPassword = 'cuba'
    }
}

configure(webModule) {
    configurations {
        webcontent
    }

    dependencies {
        compileOnly(servletApi)
        compile(globalModule)
        compile('eu.maxschuster:vaadin-signaturefield:2.0.1')
    }

    jar {
        with copySpec {
            from sourceSets.main.allJava
            include "com/ibusy2/web/toolkit/ui/client/**"
        }
    }

    task webArchive(type: Zip) {
        from file("$buildDir/web")
        from file('web')
        classifier = 'web'
    }

    artifacts {
        archives webArchive
    }

    task deployConf(type: Copy) {
        from file('src')
        include "com/ibusy2/**"
        into "$cuba.appHome/${modulePrefix}/conf"
    }

    task clearMessagesCache(type: CubaClearMessagesCache) {
        appName = "${modulePrefix}"
    }
    deployConf.dependsOn clearMessagesCache

    task cleanConf(description: 'Cleans up conf directory', type: Delete) {
        delete "$cuba.appHome/${modulePrefix}/conf"
    }

    task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) {
        appName = "${modulePrefix}"
        appJars(modulePrefix + '-global', modulePrefix + '-web')
    }

    task buildScssThemes(type: CubaWebScssThemeCreation)

    task deployThemes(type: CubaDeployThemeTask, dependsOn: buildScssThemes)

    assemble.dependsOn buildScssThemes

    task themesJar(type: Jar) {
        from file('themes')
        classifier = 'themes'
    }

    artifacts {
        archives themesJar
    }
}

configure(webToolkitModule) {
    configurations.compile {
        exclude group: 'org.springframework'
        exclude group: 'org.springframework.security.oauth'
        exclude group: 'org.eclipse.persistence'
        exclude group: 'org.codehaus.groovy'
        exclude group: 'org.apache.ant'
        exclude group: 'org.apache.httpcomponents:httpcore:4.4.12'
        exclude group: 'com.sun.mail:javax.mail:1.6.2'
        exclude group: 'org.eclipse.jetty'
        exclude group: 'com.esotericsoftware'
        exclude group: 'com.googlecode'
        exclude group: 'net.sourceforge.htmlunit'
        exclude group: 'com.sun.mail'
        exclude group: 'org.glassfish.jaxb'

        exclude group: 'com.haulmont.reports'
        exclude group: 'com.haulmont.addon.emailtemplates'
        exclude group: 'com.haulmont.addon.helium'
        exclude group: 'com.haulmont.addon.imap'
        exclude group: 'com.haulmont.addon.bproc'
        exclude group: 'com.haulmont.addon.dnd'
        exclude group: 'com.haulmont.addon.restapi'
        exclude group: 'com.haulmont.addon.dashboard'
        exclude group: 'com.google.guava'
        exclude group: 'org.apache.httpcomponents'
    }
    dependencies {
        compile(webModule)
    }

    jar {
        from sourceSets.main.allJava
    }

    task buildWidgetSet(type: CubaWidgetSetBuilding) {
        widgetSetClass = 'com.ibusy2.web.toolkit.ui.AppWidgetSet'
        shortClassPath = true
    }

    task debugWidgetSet(type: CubaWidgetSetDebug) {
        widgetSetClass = 'com.ibusy2.web.toolkit.ui.AppWidgetSet'
        shortClassPath = true
    }

    task webArchive(dependsOn: buildWidgetSet, type: Jar) {
        from file("$buildDir/web")
        classifier = 'client'
    }

    artifacts {
        archives webArchive
    }

    task deploy(dependsOn: webArchive, type: Copy) {
        from webArchive
        into "$cuba.tomcat.dir/webapps/${modulePrefix}/WEB-INF/lib"
    }
}

task undeploy(type: Delete, dependsOn: ":${modulePrefix}-web:cleanConf") {
    delete("$cuba.tomcat.dir/shared")
    delete("$cuba.tomcat.dir/webapps/${modulePrefix}-core")
    delete("$cuba.tomcat.dir/webapps/${modulePrefix}")
}

task restart(dependsOn: ['stop', ":${modulePrefix}-core:deploy", ":${modulePrefix}-web:deploy", ":${modulePrefix}-web-toolkit:deploy"], description: 'Redeploys applications and restarts local Tomcat') {
    doLast {
        ant.waitfor(maxwait: 6, maxwaitunit: 'second', checkevery: 2, checkeveryunit: 'second') {
            not {
                socket(server: 'localhost', port: '8787')
            }
        }
    }
}
restart.finalizedBy start

task buildWar(type: CubaWarBuilding) {
    includeJdbcDriver = true
    appProperties = ['cuba.automaticDatabaseUpdate': true]
    webXmlPath = 'modules/web/web/WEB-INF/single-war-web.xml'
    logbackConfigurationFile = 'etc/logback.xml'
}

Hi,
Try to make premium repository to be the last in the list, maybe it will help.
We met similar problems in the past.

Hi @albudarov

I did, no changes.

Is there a way to instruct gradle the update policy for repositories like it is possible in maven ? I found nothing useful on the net.

How did you solve this issue in the past ?

Regards
Michael

I moved premium repository to the bottom of the list.

Default Gradle policy for snapshots is to cache for 1 day. It shouldn’t be a problem.

There could be some problems with your custom repository. The clue can be found in the debug logs.

When you build from the command line, debug logs are enabled with the “-i” command line key.

When you resolve the project in the IDEA, getting Gradle debug logs is trickier. Here is a Gradle code that you might need to add the build script: https://youtrack.jetbrains.com/issue/IDEA-191119

Things are getting more clear. I ran gradle -d deploy and got interesting output.

image

Caused by: org.gradle.internal.resource.transport.http.HttpErrorStatusCodeException: Could not GET ‘https://repo.cuba-platform.com/content/groups/premium/org/webjars/npm/codemirror-formatting/maven-metadata.xml’. Received status code 403 from server: Forbidden

All errors are about org/webjars/npm, I have no such dependency in the project, is it a dependency of cuba platform ?

Michael

Hi,
This artifact can be a transitive dependency from CUBA web client or one of add-ons.

We have cleared the cached data for this artifact in the repository, please try if it helped.

Hi Alexander,

I still have the same issue, 1206 errors, 403 forbidden.

Michael

Does the error message reference the same npm package, or another one?

Exactly the same : Caused by: org.gradle.internal.resource.transport.http.HttpErrorStatusCodeException: Could not GET ‘https://repo.cuba-platform.com/content/groups/premium/org/webjars/npm/codemirror-formatting/maven-metadata.xml’. Received status code 403 from server: Forbidden

In fact, I have literally the same output than before, 1206 errors all related to org.webjars.npm. full log is attached.

build errors org.webjars.npm.txt (1.0 MB)

Hi,
We have reproduced the problem locally.
It happens when the project has some paid addon (e.g. BProc) and one of (Email Templates or GrapesJS) addons.

It is related to the Gradle caching mechanism, premium repository configuration and nature of the webjars transitive artifact dependencies with dynamic version range.

For now we could not find a quick solution. Will will let know here if find any.

Ok thanks @albudarov. Waiting for a solution then.
Michael

Hi Michael,

we’ve done a couple of configuration changes on the repository. Could you please check if the problem still persists?

Hi @gorbunkov,
Just tried. It had to redownload every pom the first time, but now it works like a charm.
Thanks !
Michael

1 Like