ml-gradle icon indicating copy to clipboard operation
ml-gradle copied to clipboard

add tasksToDisable to ml-gradle

Open peetkes opened this issue 4 years ago • 1 comments

It would be very handy if one could specify a comma separated list of gradle tasks to disable. We now solved it like below snippet:

if ( environmentNameLabel != 'local' ) {
    // in non local we are only allowed to run:
    // dhl* tasks
    // the following allowedTasks which are required to run mlRedeploy
    gradle.taskGraph.whenReady { taskGraph ->
        def tasks = taskGraph.getAllTasks()
        tasks.findAll { task ->
            // this are the tasks from 'apgDeploy'
            def allowedTasks = [
                    // required for mlRedeploy
                    'mlPrepareBundles',
                    'hubDeleteModuleTimestampsFile',
                    'mlDeleteModuleTimestampsFile',
                    'mlClearModulesDatabase',
                    'mlDeleteResourceTimestampsFile',
                    'deleteModuleTimestampsFile',
                    'hubDeploySecurity',
                    'mlLoadModules',
                    'mlReloadModules',
                    'hubPreInstallCheck',
                    'mlDeployDatabases',
                    'mlPrepareRestApiDependencies',
                    'mlDeployApp',
                    'mlPostDeploy',
                    'mlDeploy',
                    'deployQcBrand',
                    'mlRedeploy']
            if ( !task.name.startsWith("dhl") && ( task.name in allowedTasks) == false )  {
                task.enabled=false
                throw new GradleException("In non-local mode you are not allowed to run task ["+task.name+"] ")
            }
        }
    }
}

This specifies a list of allowed tasks so maybe it should cater for both: tasksToDisable and/or tasksToEnable

peetkes avatar Mar 13 '20 16:03 peetkes

Could be boilerplate code in comment as well. I did something similar to disable mlUnitTest if mlTestRestPort was empty or zero.

grtjn avatar Apr 21 '21 12:04 grtjn

@peetkes I did a quick prototype and verified that this would be easy to support... but I'm reluctant to do so because 1) it's a generic Gradle concern, and 2) based on https://stackoverflow.com/questions/47192746/how-can-i-disable-a-task-in-build-gradle , there are multiple ways to do this.

And it looks like this is the simplest way to do it, which results in the task being skipped if it's invoked:

mlDeployUsers.enabled=false
mlDeployRoles.enabled=true

So I'm closing this, as I don't think there's enough value here for ml-gradle to be doing something that's so generic to Gradle and doesn't have anything to do with MarkLogic.

rjrudin avatar Aug 10 '23 18:08 rjrudin