0

I am new to gradle. When running the gradle build task in intelliJ, my task keep running infinitely and never completed. The task is written as follows:

task webjar(type: Jar) {
    from(fileTree("build")) {  
        into "META-INF/resources"
    } 
}
jar.finalizedBy('webjar')

Can anybody help me in pointing out if I am doing anything wrong here?

update: When i am writing the task as follows it finishes successfully:

task webjar(type: Jar) {
    destinationDir file("${projectDir}/build")
    from(fileTree("build")) {  
        into "META-INF/resources"
    } 
}

Thanks,

Manish
  • 1,274
  • 3
  • 22
  • 59
  • Why do you want to pack all the files in the temporary `build` directory into a `.jar` file? I would guess that some files in the directory are locked by Gradle during the execution, mainly the files regarding the current task. – Lukas Körfer Feb 17 '20 at 11:08
  • @lukas what should be the correct task.Its a react app. – Manish Feb 17 '20 at 11:32
  • @LukasKörfer how should i fix that – Manish Feb 18 '20 at 05:06

1 Answers1

0

The issue is that you are attempting to pack the whole build folder into that jar, which includes all the project output.

So that is most likely the issue there. build should not be what you package in META-INF/resources.

Instead you will need to identify which task produces the content to be included in META-INF/resources and use its output as the from argument.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43
  • I understand what you are saying but the same project successfully gets built on windows machine.I am facing this issue on Ubuntu. – Manish Feb 18 '20 at 10:28
  • 1
    Still pretty sure you do not want to have the whole `build` content in there. So instead of focusing on the difference between platforms, I would fix the root cause and better select what needs to land inside `META-INF/resources` – Louis Jacomet Feb 18 '20 at 10:30
  • Other thing is when i am adding one more field in the above task destinationDir file("${projectDir}/build") then I am able to build the jar successfully. – Manish Feb 18 '20 at 10:30
  • Can you explain with a small example how can i achieve the same using the previous task output – Manish Feb 18 '20 at 10:39