Gradle dynamic task not executed

Hello All,

I am using gradle 7.4.2 version in java application. I need to combine and minify js files in different sets. I have declared these files sets something like this:

conf.jsAngular17v18 = [
    [
     	"name": "common",
 		"source":
 		[
 			"${conf.resourceSrcAngular17v18}/utils/abc.js",
	 		"${conf.resourceSrcAngular17v18}/js/libs/xyz-touch-punch.js",
	 		"${conf.resourceSrcAngular17v18}/js/constant.js",
	 		"${conf.resourceSrcAngular17v18}/app/app.js",
	 		"${conf.resourceSrcAngular17v18}/controller/abcd.js",
			"${conf.resourceSrcAngular17v18}/controller/xyzs.js",
			"${conf.resourceSrcAngular17v18}/controller/abcv.js",
			"${conf.resourceSrcAngular17v18}/service/tyd.js",
			"${conf.resourceSrcAngular17v18}/service/services.js",
			"${conf.resourceSrcAngular17v18}/service/dfgh.js",
			"
		]
    ],
    [
        "name": "utils",
        "source":
        [
         	"${conf.resourceSrcAngular17v18}/js/customizechart/util1.js",
         	"${conf.resourceSrcAngular17v18}/js/customizechart/util2.js",
         	"${conf.resourceSrcAngular17v18}/js/customizechart/util3.js",
         	"${conf.resourceSrcAngular17v18}/js/customizechart/util4.js",
         	"${conf.resourceSrcAngular17v18}/js/customizechart/util5.js",
         	"${conf.resourceSrcAngular17v18}/js/customizechart/util6.js",
         	"${conf.resourceSrcAngular17v18}/js/customizechart/util7.js"
        ]
    ]
]

then i have created task as below

ext.dynamicTaskList=""
ext.minifyTaskList=""
task generateMinifyJsTask {
	println "****************************generateMinifyJsTask***************************"
	doFirst {

		
		conf.jsAngular17v18.each  { jsAngular17v18->
			createCombineTaskForAngular17V18(jsAngular17v18, conf)
			createMinifyJsTaskForAngular17V18(jsAngular17v18, conf)
		}
		
	}
	doLast{
			sleep(1000)
			
		}
		
		
}
def createCombineTaskForAngular17V18(js, conf){
	println "***************************************1************************************"
	def currentMillis = new Date().getTime();
	def dynamicTaskIndex = 1
	def dynamicTask = "combine-${js.name}-${currentMillis}.js"
    task "${dynamicTask}"(type:com.eriwen.gradle.js.tasks.CombineJsTask) {
        source = js.source
        dest = file("${conf.resourceSrcAngular17v18}/min/${js.name}.min.js")
       
    }
    dynamicTaskList = dynamicTask;
  	println "*************************************************"+dynamicTaskList
    dynamicTaskIndex++
     
    // tasks."$dynamicTask".execute() -//not working in gradle 7.4.2
   
    
}
def createMinifyJsTaskForAngular17V18(js, conf){
	
	println "**********************$dynamicTaskList**********************************"+dynamicTaskList
	println "************************************2*******************************************"
	def baseName = "${conf.resourceSrcAngular17v18}/min/${js.name}"
	def currentMillis = new Date().getTime();
	def dynamicTask = "minify-${js.name}-${currentMillis}.js"
    task "${dynamicTask}"(type:com.eriwen.gradle.js.tasks.MinifyJsTask){
    dependsOn dynamicTaskList
    source = file("${baseName}.min.js")
    dest = file("${baseName}.min.js")
    closure {
                compilationLevel = 'SIMPLE_OPTIMIZATIONS'
              }
    
    }
    minifyTaskList=dynamicTask;
   
    
}

I am not getting any gradle error. but minified js are not getting created in mentioned directory.

NOTE : This was working just fine before upgrading gradle to 7.4.2
Previous code was

def createCombineTaskForAngular17V18(js, conf){
	def currentMillis = new Date().getTime();
    return tasks.create("combine-${js.name}-${currentMillis}.js", com.eriwen.gradle.js.tasks.CombineJsTask) {
        source = js.source
        dest = file("${conf.resourceSrcAngular17v18}/min/${js.name}.min.js")
      
    }
}
def createMinifyJsTaskForAngular17V18(js, conf){

	def baseName = "${conf.resourceSrcAngular17v18}/min/${js.name}"
	def currentMillis = new Date().getTime();
    tasks.create("minify-${js.name}-${currentMillis}.js", com.eriwen.gradle.js.tasks.MinifyJsTask){
        source = file("${baseName}.min.js")
        dest = file("${baseName}.min.js")
    }
}

Any help or suggestion would be appreciated.

Many Thanks

Pretty interesting question. @Vampire Can you please look into it?

It’s actually neither much interesting, nor will I have a deeper look.

  1. That code makes my eyes and heart bleed.
  2. It is pretty rude to randomly ping someone for getting an answer faster just because I tend to often answer questions. I’m just a user like you spending his spare time here, not a paid supporter.

But the main problem probably is, that the tasks are created during execution time of another task.
I seriously doubt it ever worked like that and would really wonder if it actually did.