1

I am using a gradle task to generate some code for my API and store this code into the build folder. When I am building my application the process deletes the build folder.

Is there a way to call my code generation task between the folder deletion and the start of the compilation?

Pranjal
  • 8,083
  • 3
  • 8
  • 13
  • Are you using a custom gradle task? Please show how you generate the code for your API. In gradle you can make your custom tasks depend on other tasks. You could hook in your custom code generation: https://stackoverflow.com/questions/21612729/understanding-gradle-task-dependency-dependson – ChristianB Dec 29 '20 at 13:46
  • I know how how to call other tasks , but my problem is to call my task on time after the build folder have been deleted and put my generated code in there , so the compile will find the classes that i need. – Vaggelis Larios Dec 29 '20 at 13:50

2 Answers2

0

I am not a Gradle expert, so their might be better answers!

In your build.gradle you can create custom tasks and make them depend on other tasks:

// this is your new task
task generateCode() {
  description 'Generates some code...'
  doLast {
    println("generateCode")
    // do your code generation here
  }
}

// put the name of the task you wanna depend on, like: compileSources
project.task("compileSources").dependsOn generateCode

When you call this task ./gradlew compileSources you should see that the custom task generateCode gets executed first.

ChristianB
  • 2,452
  • 2
  • 10
  • 22
0

After allot of trying , i found the solution . In the build.gradle i had to add the preBuild.finalizedBy(generateCode)