Why codes in a jar task or a war task are executed when I run gradle clean task?

apply plugin: ‘java’ //apply plugin: ‘groovy’ //apply plugin: ‘application’

sourceSets {

main {

java {

srcDir ‘src’

}

} } //mainClassName = “HelloWorld”

//applicationDefaultJvmArgs = ["-jar Hello.jar"]

task execute(type: JavaExec) {

main = ‘HelloWorld’

//classpath configurations.runtime

classpath = files(’./build/libs/*’) }

jar{

println ‘fdsafasdfasdfasdfasd’

manifest {

attributes (

‘Main-Class’: ‘HelloWorld’)

} }

[zhiming@localhost Hello]$ gradle buil fdsafasdfasdfasdfasd :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :jar UP-TO-DATE :assemble UP-TO-DATE :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test UP-TO-DATE :check UP-TO-DATE :build UP-TO-DATE

BUILD SUCCESSFUL

Total time: 4.589 secs [zhiming@localhost Hello]$ gradle clean fdsafasdfasdfasdfasd :clean

BUILD SUCCESSFUL

Total time: 2.355 secs

Because the ‘println’ statement is being executed during build configuration therefore it will execute when any tasks are run. If you want that code to run only when the ‘jar’ task is executed then place it in a task action closure.

jar {

doLast {

println ‘hello’

}

}

Yes. Get it after post it. Thank you all the same.

Yes. Get it after post it. Thank you all the same