Recently, I was working on a project with both Java and Kotlin code, using PMD for Java and detekt for Kotlin. Occasionally it was necessary to suppress a warning, and it was easy to confuse the syntax when switching between the two.


Java - PMD

In Java, annotate your class or method with the @SuppressWarnings annotation, and prefix the rule name with PMD:

@SuppressWarnings("PMD.AvoidLiteralsInIfCondition") 
public abstract class ServiceBase...

You can also supply an array:

@SuppressWarnings({"PMD.AvoidLiteralsInIfCondition", "PMD.LongMethod"})
public class Query...

Kotlin - detekt

For detekt, the annotation is named @Suppress:

@Suppress("LongMethod", "MaxLineLength")
object SelectableGenerator...

Constants

Another useful tip, to avoid breaking rules like MagicNumber, is to use constants.

In Java, this is simple enough:

private static final int MAX_TRIES = 3;

In Kotlin, you can declare a class-level constant using a companion object:

companion object {
    private const val MAX_TRIES = 3
}

I hope you find this useful.