Task executed automatically


(Balusamy N) #1

Hi, I am using gradle 1.10.

I have 2 issues. 1. I am defining copule of taskes they are automatically executed even if i am not calling

  1. I am doing js minification

  2. copying and renaming the source js file which is in the build directory

  3. Now i have list of 2 files one is the source file and another is renamed file xxx-src-1.0.0.js

  4. Try to read the files from the build folder,the files are not pickedup from the build path,i think it is not generated.

Can you please help me in this


(René Groeschke) #2

Hi, 1) is a problem, beginner often run into. have a look at http://forums.gradle.org/gradle/topics/why_is_my_task_being_executed for clarification

  1. Can you rephrase your second problem? I can’t follow on this one.

cheers, René


(Balusamy N) #3

Hi, thank you ,for the first issue

2nd problem. 1. I am trying to minify copule of js files 2. I am coppying AAAA.js to the build folder 3. renaming the file in to AAA-src-1.0.0.js, step 2,3 are working fine 4. try to read the files from the folder and iterate it and minify

When i am reading the files AAAA.js and AAA-src-1.0.0.js file it is not available…so i am unable to minify it.but the files are available in the build folder


(Balusamy N) #4

Hi, I am able to solve the issue, After coping the files, i called the configuration again ,now file reading part is working fine.

But my minified task is not working, i think i am missing some thing, Can you please help me

task minifyJSFile(){

println ‘minify called 1’

doFirst {

javascript.source {

dev {

js {

//srcDir “${projectDir}/src/main/resources”

//srcDir “${sourceSets.main.output.resourcesDir}”

srcDir “${jstemp}”

include “**/*.js”

exclude “**/-src-.js”

}

}

}

println ‘minify called 2’+javascript.source.dev.js.files

javascript.source.dev.js.files.eachWithIndex { jsFile, idx ->

tasks.add(name: “minifyEachJs${idx}”, type: com.eriwen.gradle.js.tasks.MinifyJsTask) {

source = jsFile

String fileName = “${jsFile.name}”

println “Minimizing File:::::::::::::::::::::::::::::::::::::::::::::” + fileName

String renamedFile = fileName.replaceFirst(~/.[^.]+$/, ‘’) + “-${pocVersion}” + fileName.replaceFirst(fileName.replaceFirst(~/.[^.]+$/, ‘’),’’)

println “Minimizing File:::::::::::::::::::::::::::::::::::::::::::::” + renamedFile

println “Minimizing File:::::::::::::::::::::::::::::::::::::::::::::” + jsFile.parent

dest = “${jsFile.parent}/${renamedFile}”

sourceMap = file("${jsFile.parent}/${jsFile.name.replaceFirst(~/.[^.]+$/, ‘’)}.sourcemap.json")

}

}

} }

====================== my execution task below build.doLast{ tasks.copyJs.execute()

tasks.minifyJSFile.execute() }


(Balusamy N) #5

HI ,It worked fine with the following code i called the task but not executed,

task minifyJSFile(){

println ‘minify called 1’

doFirst {

javascript.source {

dev {

js {

srcDir “${sourceSets.main.output.resourcesDir}”

include “**/-src-.js”

}

}

}

println ‘minify called 2’+javascript.source.dev.js.files

javascript.source.dev.js.files.eachWithIndex { jsFile, idx ->

tasks.add(name: “minifyEachJs${idx}”, type: com.eriwen.gradle.js.tasks.MinifyJsTask) {

source = jsFile

String fileName = “${jsFile.name}”

println “Minimizing File:::::::::::::::::::::::::::::::::::::::::::::” + fileName

String renamedFile = (fileName =~ /-src-/).replaceAll("-")

dest = “${jsFile.parent}/${renamedFile}”

sourceMap = file("${jsFile.parent}/${(renamedFile =~ /.js/).replaceAll("")}.sourcemap.json")

}

}

tasks.findAll { task ->

if(task.name.startsWith(“minifyEachJs”))

task.execute()

}

} }