Clean task fails

Hi,

When running “Clean” from the Run menu, I get the following error.
Why did I do wrong?? :slight_smile:


FAILURE: Build failed with an exception.  * What went wrong: Execution failed for task ':clean'. > Unable to delete file: C:\Users\xxx\studio-projects\toj\build\hsqldb\toj\toj.lck  * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.  BUILD FAILED  Total time: 0.635 secs [21:08:15.159] Task 'clean' failed
org.gradle.api.file.UnableToDeleteFileException: Unable to delete file: C:\Users\xxx\studio-projects\toj\build\hsqldb\toj\toj.lck

This is strange. Clean task should not remove files inside the top-level build directory, let alone database related files.
Have you added something to your build.gradle manually?
Could you attach it here?

Hi, apologies for the late reply.
I started a new project to test but soon the same error occurred. I have not modified the gradle build script manually.
Here is the file content:



buildscript {
    ext.cubaVersion = '6.1.2'
    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"
    }
}

def globalModule = project(':app-global')
def coreModule = project(':app-core')
def guiModule = project(':app-gui')
def webModule = project(':app-web')

def servletApi = 'org.apache.tomcat:tomcat-servlet-api:8.0.26'
apply(plugin: 'eclipse')
apply(plugin: 'java')
apply(plugin: 'cuba')

cuba {
    artifact {
        group = 'com.company.tojm'
        version = '0.1'
        isSnapshot = true
    }
    tomcat {
        dir = "$project.rootDir/build/tomcat"
    }
    ide {
        copyright = '''Copyright (c) ${today.year} ${project.name}''' // Copyright Notice for IDEA project
        classComment ='''/**
 * @author ${USER}
 */'''
        
    }
}

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

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

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

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

    artifacts {
        archives sourceJar
    }
}

configure(globalModule) {
    dependencies {
        compile("com.haulmont.cuba:cuba-global:$cubaVersion")

    }

    task enhance(type: CubaEnhancing)
    
}

configure(coreModule) {

    configurations {
        jdbc
        dbscripts
    }

    dependencies {
        compile(globalModule)
        provided(servletApi)
        jdbc(hsql)
        testRuntime(hsql)
        compile("com.haulmont.cuba:cuba-core:$cubaVersion")
        testCompile("com.haulmont.cuba:cuba-core-tests:$cubaVersion")
        testCompile("com.haulmont.cuba:cuba-shared-lib:$cubaVersion")
        dbscripts("com.haulmont.cuba:cuba-core:$cubaVersion:db@zip")

    }

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

    task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) {
        appName = 'app-core'
        appJars('cuba-core', 'cuba-global', 
                'app-global', 'app-core')
    }

    task createDb(dependsOn: assembleDbScripts, description: 'Creates local database', type: CubaDbCreation) {
        dbms = 'hsql'
        dbmsVersion = 'null'
        host = 'localhost'
        dbName = 'tojm'
        dbUser = 'sa'
        dbPassword = ''
    }

    task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) {
        dbms = 'hsql'
        dbmsVersion = 'null'
        host = 'localhost'
        dbName = 'tojm'
        dbUser = 'sa'
        dbPassword = ''
    }
}

configure(guiModule) {
    dependencies {
        compile(globalModule)
        compile("com.haulmont.cuba:cuba-gui:$cubaVersion")
        testCompile("com.haulmont.cuba:cuba-client-tests:$cubaVersion")

    }

    task deployConf(type: Copy) {
        from file('src')
        include "com/company/tojm/**"
        into "$cuba.tomcat.dir/conf/app"
    }
}

configure(webModule) {
    configurations {
        webcontent
        
    }

    dependencies {
        provided(servletApi)
        compile(guiModule)
        compile("com.haulmont.cuba:cuba-web:$cubaVersion")
        webcontent("com.haulmont.cuba:cuba-web:$cubaVersion:web@zip")
        webcontent("com.haulmont.cuba:cuba-web-toolkit:$cubaVersion:web@zip")
        testCompile("com.haulmont.cuba:cuba-client-tests:$cubaVersion")

    }

    task webArchive(type: Zip) {
        from file('web')
        classifier = 'web'
    }

    artifacts {
        archives webArchive
    }

    task deployConf(type: Copy) {
        from file('src')
        include "com/company/tojm/**"
        into "$cuba.tomcat.dir/conf/app"
    }

    task clearMessagesCache(type: CubaClearMessagesCache) {
        appName = 'app'
    }
    deployConf.dependsOn clearMessagesCache

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

    task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) {
        appName = 'app'
        appJars('cuba-global', 'cuba-web', 'cuba-rest-api', 'cuba-client', 'cuba-gui', 
                'app-global', 'app-gui', 'app-web')
    }
}




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

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

task wrapper(type: Wrapper) {
    gradleVersion = '2.6'
}

apply from: 'extra.gradle'

Hi Matthis,
Thank you for the explanation, we have found the cause.
You use Eclipse, so Studio adds “java” Gradle plugin to the root of build.gradle for correct generation of Eclipse project files. It causes deletion of build folder in the project root directory when the “clean” task executes. This is really a major problem, so we will try to fix it in the recent Studio release. Until then, either switch to another database (PostgreSQL for example), or use IntelliJ instead of Eclipse, or never call clean task.

Thank you for your prompt support!
Best regards,

Matthis

The problem is fixed in the platform version 6.1.4