JavaCompile task in the execution phase

Hello, I have just started to learn gradle, I have some trouble with creating JavaCompile task during the execution phase. I have tried the doLast but the compile task does always nothing. I have also checked if the compile task is correcte it works fine in the configuration phase. Thank you for your answers

task InstanceCreateBin(type: JavaCompile)<<{
  source = sourceSets.myproject.java.srcDirs
  classpath = sourceSets.myproject.runtimeClasspath
  destinationDir=file("$buildDir/bin")
   }

you accidently used the leftshift operator ("<<") (which is a shortcut for a doLast block). please try again with

task InstanceCreateBin(type: JavaCompile){
  source = sourceSets.myproject.java.srcDirs
  classpath = sourceSets.myproject.runtimeClasspath
  destinationDir=file("$buildDir/bin")
}

Thank you Rene for your answer. Maybe I haven’t provide more details about my situation. It’s not an accident actually I know that "<< " is equivalent to doLast . Here the situation:

apply plugin: 'java'
sourceSets{
  myproject{
     java.srcDirs=[
      'backend',
      'shared',
      'dashboard_web',
      'gwt_common',
      'admin_web',
      'surveys-backend',
      'widgety',
      "$buildDir/home/publication-log/instances/$customer/configuration",
      'customer_specific_data'
      ]
          compileClasspath= sourceSets.main.output+ configurations.myproject
    runtimeClasspath= output+compileClasspath
}
}

and then I create “InstanceCreateBin” task:

task InstanceCreateBin(type: JavaCompile){
  source = sourceSets.myproject.java.srcDirs
  classpath = sourceSets.myproject.runtimeClasspath
  destinationDir=file("$buildDir/bin")
}

Well gradle has created automatically compilemyprojectJava processMYPROJECTJava…

and when I run “InstanceCreateBin” the build will run compilemyprojectJava which compile successfully and then back to “InstanceCreateBin” for recompiling. That why I look to do once the compiling or to make InstanceCreateBin task running only in the execution phase and not calling "compilemyprojectJava "

In other word I would like that the destinationDir is only “$buildDir\bin” and not into “classes” and again in “$buildDir\bin” as result for this code.

Thank you again for your answers :slight_smile:

Why do you add another ‘JavaCompile’ task, instead of reconfiguring ‘compilemyprojectJava’ or ‘sourceSets.output.classesDir’?

I would be happy if you explain me how to reconfigure a gradle task. Thank you Peter

compileMyprojectJava {
   // configure it any way you like
}

Some compile settings (e.g. ‘compileClasspath’ and ‘classesDir’) can also be configured on ‘sourceSets.myproject.output’.

Here is my solution:

sourceSets{
  myproject{
     java.srcDirs=[
      'backend',
      'shared',
      'dashboard_web',
      'gwt_common',
      'admin_web',
      'surveys-backend',
      'widgety',
      "$buildDir/home/publication-log/instances/$customer/configuration",
      'customer_specific_data'
      ]
       }
       compileMyprojectJava{
  compileClasspath= sourceSets.myproject.output+ configurations.myproject
  runtimeClasspath= sourceSets.myproject.output+compileClasspath
  classesDir=file("$buildDir/bin")
  srcDirs = sourceSets.myproject.java.srcDirs
    }
  check.dependsOn compileMyprojectJava

Always the “$buildDir\bin” is not created

Thank you for your helps