Gradle deployment problem - files written to deploy sub-directory but then immediately deleted

Hello Everyone

I am having difficulty with the Gradle deployment procedure and need some clarification and assistance.

Local Development Environment:
CUBA Platform version: 7.2.10
CUBA Studio plugin version: 15.1-202
IntelliJ version: CUBA Studio 2020.2
Datebase: MySQL 8.0.19
Operating System: macOS Big Sur 11.2 (20D64)
Browser: Safari 14.0.3 (16610.4.3.1.4)
Hardware: iMac (Retina 5K, 27-inch, 2020)
Graphics: AMD Radeon Pro 5700 8 GB
File System: Case-Sensitive Journaled HFS+ (APFS)

Use Case: I need to copy several static HTML and PDF files into the “deploy” directory tree, so that I can display them in a BrowserFrame fragment.

Source Path: /modules/web/src/com/company/demo/html
Destination Path: /deploy/app_home/app/conf/com/company/demo/html

(Note: I have tried other Source Paths without success.)

This is my very first time modifying a CUBA build.gradle file, so I decided to try and explicitly code my own primitive task named “deployStaticWebResources” (class StaticWebResourcesTask extends DefaultTask) and not modify the other tasks except for a few dependencies.

Problem: If I run the “deployment->deploy” task by itself in CUBA Studio it works as expected; my destination directory tree is created and my two test files are copied into the destination directory. My “println” output is also displayed in the order that I expect it….

Task :app-web:assemble UP-TO-DATE
Task :app-web:cleanConf

Task :app-web:deployStaticWebResources
Deploy HTML resources - SRC dir: /Users/bhc/Development/Projects/CUBA/src/examples/anonymous-screens-access/modules/web/src/com/company/demo/html
Deploy HTML resources - DES dir: /Users/bhc/Development/Projects/CUBA/src/examples/anonymous-screens-access/deploy/app_home/app/conf/com/company/demo/html

Task :app-web:deploy

However, if I run the entire “CUBA Application” build and run/debug task in CUBA Studio I see my “println” output but I also see the “deploy/app_home/app/conf/com” directory of my destination being created but then “com” and everything below it is immediately deleted during this procedure. My new directories and files are gone.

What task is deleting my directories and why? What am I missing or doing wrong?

If I enter the following commands in the CUBA Studio terminal, then my destination directories are created and the files are copied and everything is still there after I start the application:

sh gradlew build
sh gradlew deploy
sh gradlew start

Please note that I also tried the suggestion found here: Add files to conf directory from IntelliJ - CUBA.Platform but I could not get it to work either.

Could someone please explain what is happening here and make a suggestion how I can avoid it. Here is my demo project: anonymous-screens-access.zip (96.6 KB)

Many thanks in advance!

Best regards
Chris

Hi,
The cleanConf task is the task that cleans the deploy/app_home/app/conf folder.
You need to configure your deployStaticWebResources task to run after cleanConf.

How to do that - can be easily searched in the internet or in the Gradle documentation:

https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:ordering_tasks

Use “shouldRunAfter” or “dependsOn”.

@AlexBudarov
Hi Alex

Thank you for your feedback. My task already depends on cleanConf:

task deployStaticWebResources(dependsOn: cleanConf, type: StaticWebResourcesTask)

and in the log output (in my original description above) you see my task running after cleanConf and before deploy, which I modified to depend upon my task instead of cleanConf, so that the order is correct. That is why I am confused. It appears to me that cleanConf is running a second time after my task or after the deploy task but I cannot figure out how this could happen and I do not see it in the log output.

I was not aware of the “shouldRunAfter” designation but I just tried this with (without any other modifications)…

deployStaticWebResources.shouldRunAfter cleanConf

and that did not change the result. I also tried this constellation…

task deployStaticWebResources(type: StaticWebResourcesTask) {
    htmlSrcPath = "$rootProject.rootDir/modules/web/src/com/company/demo/html"
    htmlDesPath = "$cuba.appHome/${modulePrefix}/conf/com/company/demo/html"
    println "Configure: deployStaticWebResources"
}

deployStaticWebResources.shouldRunAfter cleanConf

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

but the result is the same; my directories and file are copied and then deleted.

I also just tried this…

task deployStaticWebResources(type: StaticWebResourcesTask) {
    htmlSrcPath = "$rootProject.rootDir/modules/web/src/com/company/demo/html"
    htmlDesPath = "$cuba.appHome/${modulePrefix}/conf/com/company/demo/html"
    println "Configure: deployStaticWebResources"
}

deployStaticWebResources.shouldRunAfter cleanConf

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

deploy.finalizedBy deployStaticWebResources

but it did not help either.

Do you have any other suggestions? Thanks in advance.

Best regards
Chris

Hi,
I’ve checked, and it appears that cleanConf is executed one more time separately from deploy as one of “Before launch” steps of the CUBA Application configuration.
So we need to invoke deployStaticWebResources every time after cleanConf.

This will work:

cleanConf.finalizedBy deployStaticWebResources

// delete
// deploy.finalizedBy deployStaticWebResources

// delete
// deployStaticWebResources.shouldRunAfter cleanConf

@AlexBudarov
Hi Alex
Thank you very much for the information and your assistance! I tried your suggestion and it worked correctly, so this problem has been solved.

Before reporting this behavior I searched through the GitHub sources but could not find this internal build procedure or CUBA specific Gradle classes anywhere. Would it be possible for you to publish them or provide more documentation? I think that would save some people a lot of time and effort when they are customizing their Gradle configuration. I am very happy that it works now but it is still not that transparent to me. Just a thought.

Thanks again!
Chris