"Task with name 'build' not found in root project" after adding Gradle Release Plugin

Hello,

I want to integrate the Gradle Release Plugin into an existing CUBA application. This has always worked in other projects so far. But now I get the error message " Task with name ‘build’ not found in root project" after I have add the plugin section

plugins {
    id 'net.researchgate.release' version '2.6.0'
}

and I can’t find the cause.

build.gradle:

buildscript {
    ext.cubaVersion = '7.1.1'
    repositories {
        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')
            }
        }
        
    }
    dependencies {
        classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7"
    }
}

plugins {
    id 'net.researchgate.release' version '2.6.0'
}

def modulePrefix = 'app'

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

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

apply(plugin: 'cuba')
apply(plugin: 'org.sonarqube')


sonarqube {
    properties {
        property "sonar.host.url", "https://sonar.i"
        property "sonar.login", "xxxx"
        property "sonar.password", "xxxx"
        property "sonar.scm.disabled", "true"
        property "sonar.projectName", "ATKearnyTest"
        property "sonar.java.binaries", "modules/**/build/**"
        property "sonar.projectKey", "atkearnytest"
        property "sonar.exclusions", "modules/web/build/themes-tmp/**, modules/web/themes/**, modules/web/web/**, modules/web/build/tmp/**, modules/web/build/distributions/**, modules/web/build/web/**, /modules/global/build/tmp/**, modules/core/test/**, modules/core/build/tmp/**,  modules/core/build/db/**, modules/core/build/distributions/**, modules/core/db/**"
    }
}

cuba {
    artifact {
        group = 'de.agentes.atkearneytest'
        version = project.properties['version'].replaceAll('-SNAPSHOT', '')
        isSnapshot = project.properties['version'].contains('-SNAPSHOT')
    }
    tomcat {
        dir = "$project.rootDir/deploy/tomcat"
    }
}

dependencies {
    appComponent("com.haulmont.cuba:cuba-global:$cubaVersion")
    appComponent('com.haulmont.addon.restapi:restapi-global:7.1.0')
    appComponent("com.haulmont.reports:reports-global:$cubaVersion")
    appComponent('de.diedavids.cuba.runtimediagnose:runtime-diagnose-global:1.4.1')
}

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

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

    dependencies {
        testCompile('junit:junit:4.12')
    }

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

    artifacts {
        archives sourceJar
    }
}

configure(globalModule) {
    dependencies {
        if (!JavaVersion.current().isJava8()) {
            runtime('javax.xml.bind:jaxb-api:2.3.1')
            runtime('org.glassfish.jaxb:jaxb-runtime:2.3.1')
        }
    }

    entitiesEnhancing {
        main {
            enabled = true
        }
    }
}

configure(coreModule) {

    configurations {
        jdbc
        dbscripts
    }

    dependencies {
        compile(globalModule)
        compileOnly(servletApi)
        jdbc(postgres)
        testRuntime(postgres)
    }

    task cleanConf(description: 'Cleans up conf directory') {
        doLast {
            def dir = new File(cuba.tomcat.dir, "/conf/${modulePrefix}-core")
            if (dir.isDirectory()) {
                ant.delete(includeemptydirs: true) {
                    fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties')
                }
            }
        }
    }

    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) {
        dbms = 'postgres'
        host = 'localhost'
        dbName = 'atkearneytest'
        dbUser = 'postgres'
        dbPassword = 'postgres'
    }

    task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) {
        dbms = 'postgres'
        host = 'localhost'
        dbName = 'atkearneytest'
        dbUser = 'postgres'
        dbPassword = 'postgres'
    }
}

configure(webModule) {
    configurations {
        webcontent
    }

    dependencies {
        compileOnly(servletApi)
        compile(globalModule)
        compile('org.jsoup:jsoup:1.12.1')
        compile('org.asciidoctor:asciidoctorj:2.1.0')
        compile('org.asciidoctor:asciidoctorj-pdf:1.5.0-beta.5')
        compile('net.sourceforge.cssparser:cssparser:0.9.4')
        // compile('org.w3c.css:sac:1.3')
    }

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

    artifacts {
        archives webArchive
    }

    task deployConf(type: Copy) {
        from file('src')
        include "de/agentes/atkearneytest/**"
        into "$cuba.tomcat.dir/conf/${modulePrefix}"
    }

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

    task cleanConf(description: 'Cleans up conf directory') {
        doLast {
            def dir = new File(cuba.tomcat.dir, "/conf/${modulePrefix}")
            if (dir.isDirectory()) {
                ant.delete(includeemptydirs: true) {
                    fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties')
                }
            }
        }
    }

    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
    }
}

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"], description: 'Redeploys applications and restarts local Tomcat') {
    doLast {
        ant.waitfor(maxwait: 6, maxwaitunit: 'second', checkevery: 2, checkeveryunit: 'second') {
            not {
                socket(server: 'localhost', port: '8787')
            }
        }
        start.execute()
    }
}

task buildWar(type: CubaWarBuilding) {
    includeJdbcDriver = true
    singleWar = false
    appProperties = ['cuba.automaticDatabaseUpdate': true]
    appHome = '../app_home'
    logbackConfigurationFile = 'etc/war-logback.xml'
}

Thanks and best regards
Andreas

I fixed it myself by adding the following lines to the build.gradle:

release {
    buildTasks = ['buildWar']
}
1 Like

Hello,

the problem is unfortunately not yet solved. I have created an app component and added the release plugin in build.gradle:

buildscript {
    ext.cubaVersion = '7.1.3'
    repositories {
        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 'http://mvn-repo.i:8080/nexus/content/repositories/CubaComponents/'
            credentials {
                username('cuba')
                password('cuba123')
            }
        }
        
    }
    dependencies {
        classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"
    }
}

plugins {
    id 'net.researchgate.release' version '2.6.0'
}

def modulePrefix = 'helpsystem'

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

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

apply(plugin: 'cuba')

cuba {
    artifact {
        group = 'de.agentes.cuba.helpsystem'
        version = project.properties['version'].replaceAll('-SNAPSHOT', '')
        isSnapshot = project.properties['version'].contains('-SNAPSHOT')
    }
    tomcat {
        dir = "$project.rootDir/deploy/tomcat"
    }
    uploadRepository {
        url = 'http://mvn-repo.i:8080/nexus/content/repositories/CubaComponents/'
        user = 'cuba'
        password = 'cuba123'
    }
}

dependencies {
    appComponent("com.haulmont.cuba:cuba-global:$cubaVersion")
}

def hsql = 'org.hsqldb:hsqldb:2.4.1'

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

    dependencies {
        testCompile('junit:junit:4.12')
    }

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

    artifacts {
        archives sourceJar
    }
}

configure(globalModule) {
    dependencies {
        if (!JavaVersion.current().isJava8()) {
            runtime('javax.xml.bind:jaxb-api:2.3.1')
            runtime('org.glassfish.jaxb:jaxb-runtime:2.3.1')
        }
    }

    entitiesEnhancing {
        main {
            enabled = true
        }
    }

    jar {
        manifest {
            attributes('App-Component-Id': cuba.artifact.group)
            attributes('App-Component-Version': cuba.artifact.version + (cuba.artifact.isSnapshot ? '-SNAPSHOT' : ''))
        }
    }
}

configure(coreModule) {

    configurations {
        jdbc
        dbscripts
    }

    dependencies {
        compile(globalModule)
        compileOnly(servletApi)
        jdbc(hsql)
        testRuntime(hsql)
    }

    task cleanConf(description: 'Cleans up conf directory') {
        doLast {
            def dir = new File(cuba.tomcat.dir, "/conf/${modulePrefix}-core")
            if (dir.isDirectory()) {
                ant.delete(includeemptydirs: true) {
                    fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties')
                }
            }
        }
    }

    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) {
        dbms = 'hsql'
        host = 'localhost:9010'
        dbName = 'helpsystem-3LvY5qlMn'
        dbUser = 'sa'
        dbPassword = ''
    }

    task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) {
        dbms = 'hsql'
        host = 'localhost:9010'
        dbName = 'helpsystem-3LvY5qlMn'
        dbUser = 'sa'
        dbPassword = ''
    }
}

configure(webModule) {
    configurations {
        webcontent
    }

    dependencies {
        compileOnly(servletApi)
        compile(globalModule)
    }

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

    artifacts {
        archives webArchive
    }

    task deployConf(type: Copy) {
        from file('src')
        include "de/agentes/cuba/helpsystem/**"
        into "$cuba.tomcat.dir/conf/${modulePrefix}"
    }

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

    task cleanConf(description: 'Cleans up conf directory') {
        doLast {
            def dir = new File(cuba.tomcat.dir, "/conf/${modulePrefix}")
            if (dir.isDirectory()) {
                ant.delete(includeemptydirs: true) {
                    fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties')
                }
            }
        }
    }

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

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"], description: 'Redeploys applications and restarts local Tomcat') {
    doLast {
        ant.waitfor(maxwait: 6, maxwaitunit: 'second', checkevery: 2, checkeveryunit: 'second') {
            not {
                socket(server: 'localhost', port: '8787')
            }
        }
        start.execute()
    }
}

The message “Task with name ‘build’ not found in root project” appears again.

Any ideas?

Thanks and best regards
Andreas

Hi @Andreas.Brueck,

I have experienced that problem in many of my app components as well. What I know is that if you switch back the version 2.1.2 the problem disappeared.

E.g. see:

But as you see sometimes I’m also sometimes using successfully newer versions. Unfortunately for some projects it did not work to update it to >= 2.2.0.

If you don’t really need the latest updated, switching to 2.1.2 should solve the problem.

Perhaps you will find what is actually the root cause. I also looked around for other plugins that do similar things, but did not really found a lot of stuff.

Cheers
Mario

The corresponding issue is this one: https://github.com/researchgate/gradle-release/issues/186

Hi, Mario,

thank you very much, that was the solution. :slight_smile:

Many greetings
Andreas

Hi Andreas,

could you share what from the post fixed the issue for you?

Thanks & Best Regards,
Thiago

Hi @thiago.salvador.work,

were not using the Gradle Release Plugin anymore. Where now using a Jenkins pipeline:

pipeline {
    agent any

    options {
        timeout(time: 1, unit: 'HOURS')
        buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '50'))
    }

    tools {
        jdk 'OpenJDK11'
    }

    stages {
        stage('Clean Workspace and checkout') {
            steps {
                cleanWs()
                echo "Git-Url is ${GIT_URL}"
                git branch: 'release', url: "${GIT_URL}"
            }
        }

        stage('Prepare') {
            steps {
                sh '$JAVA_HOME/bin/java -version'
                sh 'chmod +x ./gradlew'
                sh './gradlew clean --no-daemon'
            }
        }

        stage('Create release version number') {
            steps {
                script {
                    def d = [version: '0.0.0']
                    def props = readProperties defaults: d, file: 'gradle.properties'
                    
                    props['version'] = props['version'].replaceAll('-SNAPSHOT', '')
                    props['build'] = "0"
                    print "New release: ${props['version']}"
                    currentBuild.description = "${props['version']}"   


                    def output = []
                    props.each { output << "$it.key=$it.value" }
                    writeFile(file: 'gradle.properties', text: output.join("\n"))
                }
            }
        }     

        stage('Build') {
            steps {
                sh './gradlew build --refresh-dependencies --no-daemon'
            }
        }

        stage('Build and archive UberJar') {
            steps {
                sh './gradlew buildUberJar --no-daemon'
                archiveArtifacts 'build/distributions/uberJar/*.*'

            }
        }

        stage('Deploy to ...') {
            steps {
                script {
                    ....
                }
            }
        }        

        stage('Commit and tag release') {  
            steps {
                script {

                    def d = [version: '0.0.0']
                    def props = readProperties defaults: d, file: 'gradle.properties'
                    def tag_name = props['version']
                    def tag_message = "New release: ${props['version']}"

                    println("Commit: ${tag_message}")
                    def branch = sh(script: "git rev-parse --symbolic-full-name --abbrev-ref HEAD", returnStdout: true).trim() as String
                    sh($/git commit -a -m "${tag_message}" && git push origin ${branch}/$)

                    println("Tagging: ${tag_name}")
                    sh($/git tag -a ${tag_name} -m "${tag_message}" && git push origin ${tag_name}/$)
                }

            }
        }        

        stage('Increase version number') {
            steps {
                script {
                    def d = [version: '0.0.0']
                    def props = readProperties defaults: d, file: 'gradle.properties'
                    def version = props['version'].replaceAll('-SNAPSHOT', '')

                    String patch = version.substring(version.lastIndexOf('.') + 1) //get last digit
                    int patchInt = patch.toInteger() + 1 //increment
                    String majorAndMinor = version.substring(0,version.lastIndexOf(".")); //get the beginning
                    version = majorAndMinor + "." + patchInt
                    props['version'] = version + '-SNAPSHOT'
                    props['build'] = "1"

                    def output = []
                    props.each { output << "$it.key=$it.value" }
                    writeFile(file: 'gradle.properties', text: output.join("\n"))

                    def commit_message = "New version: ${props['version']} Build ${props['build']}"
                    println(commit_message)
                    def branch = sh(script: "git rev-parse --symbolic-full-name --abbrev-ref HEAD", returnStdout: true).trim() as String
                    sh($/git commit -a -m "${commit_message}" && git push origin ${branch}/$)                    
                }

            }
        } 

    }

}

gradle.properties:

build=1
version=6.2.2-SNAPSHOT

Greetings
Andreas

1 Like