spotbugs / discuss

SpotBugs mailing list
6 stars 1 forks source link

Spotbugs sequential execution as gradle task #119

Open mariometushev opened 2 years ago

mariometushev commented 2 years ago

Hi guys, I have a question about spotbugs functionalities.

I want to mentioned that the project is Java multi module based. I have one Jenkins job that runs some parallel gradle tasks(up to 8) on different java project modules and static code analysis including spotbugs. The problem is that spotbugs requires a lot of memory(up to 1GB) and when I start more than one spotbugs gradle task at the same time, the Jenkins job node freezes and I have to restart the machine because some resources remain locked. I cannot decrease spotbugs memory, because some modules are big.

So my question is: Does anyone know how to make only the spotbugs task to run sequential and let the rest of the gradle tasks run in parallel? Maybe I have to put somewhere some boolean flag to indicate that i don't want to execute that task in parallel?

If you need any further information please don't hesitate to ask :)

lasselindqvist commented 2 years ago

Hi. In case of Jenkins, I would recommend using Locable Resources Plugin (https://www.jenkins.io/doc/pipeline/steps/lockable-resources/). https://stackoverflow.com/questions/56786164/jenkins-resource-locks-get-lock-for-multiple-node-specific-resources/58393432#58393432 also very well shows how you can make the locks node-specific so that it would allow different nodes to run different static analysis builds.

mariometushev commented 2 years ago

@lasselindqvist Thanks for your quick answer bro. So if I understand right, this plugin allows you to lock specific amount of RAM memory for some Jenkins job build step.

But I think that the problem is not related to Jenkins, because I just want to make spotbugs task sequential, in other words if at some point in time spotbugs is running for some java module, I want gradle to finish that task before start next spotbugs task for another module.

If I have 8 modules and Jenkins runs 8 parallel gradle tasks, for example: Module1.compile(requires a little bit of memory and needs some seconds to finish) Module2.compile(requires a little bit of memory and needs some seconds to finish) Module3.compile(requires a little bit of memory and needs some seconds to finish) Module4.compile(requires a little bit of memory and needs some seconds to finish) Module5.compile(requires a little bit of memory and needs some seconds to finish) Module6.compile(requires a little bit of memory and needs some seconds to finish) Module7.compile(requires a little bit of memory and needs some seconds to finish) Module8.spotbugs(requires 1GB RAM and needs some extra minutes to finish)

Compile gradle tasks will finish faster than spotbugs one, and if gradle start another spotbugs task for some modules, for example: Module1.spotbugs Module2.test Module3.spotbugs Module4.spotbugs Module5.spotbugs Module6.spotbugs Module7.test Module8.spotbugs

At that moment the job will need more than 6GB of RAM and I don't have that much. I don't know if you understand me right :)

I just need to tell gradle: "Hey, don't run spotbugs, because another module is now using that gradle task"

Best regards, Mario :)

lasselindqvist commented 2 years ago

If you just want one spotbugs at a time, the situation is even simpler for you. Just use

lock(label: 'spotbugs') {
    // gradle spotbugs command goes here
}

and it will only allow one single command globally.

mariometushev commented 2 years ago

@lasselindqvist Thank you man, appreciate your help. Can this plugin be used in Jenkins freestyle job instead of pipeline?

lasselindqvist commented 2 years ago

I would think you can. Best way to find out is to just install the plugin and try using it.