0

I am working on a Java project which uses MapStruct. We would like the SonarQube Java rule engine's rule "Public types, methods and fields (API) should be documented with Javadoc" to be ignored for method declarations in MapStruct's mappers, because they are self-explanatory and there is a lot of them, so it is making the sonar's issues a mess.

Is there a way to do that? I can't find any answers, but I can't imagine everyone else is typing meaningless Javadocs to fulfil the rule.

Jarmila
  • 1
  • 1
  • 1
    Hi Jarmila, I think you can achieve this using the sonar-project.properties file like here: https://stackoverflow.com/a/65340805/3154883 – Brother Jan 11 '21 at 12:24
  • Have you tried to apply `@SuppressWarnings( "javadoc" )` to the respective class or to each element that lacks the documentation? I do not know SonarQube, so I do not know whether it honours the annotation, but it may be worth a try. – tquadrat Jan 11 '21 at 12:34
  • Hi @Brother, thank you for the tip. I'll have look at it. tquadrat thank you, I also ran into this possibility used in different cases when I was googling and I gave it a try but it did not work :\ – Jarmila Jan 11 '21 at 12:43
  • @tquadrat I've found out that instead of @SuppressWarnings("javadoc"), which does not work, I can use @SuppressWarnings("squid:S1176") which works. But I have to annotate all the methods or at least all the "mapper" interfaces which they are in. That does not seem elegant though. It would be great if I could somehow use the annotation in the MapStructGlobalConfig and it was then applied to all the mapper methods. I've experimented with it a little but I didn't manage to make it work. – Jarmila Jan 11 '21 at 15:58
  • @Brother It seems like with the sonar-project.properties I can only exclude whole files so that the specified rules are not being applied on them. We tend to keep the mapper interface in one file along with the class that calls the mapping methods, so I would have to exclude more code than I need to or change the convention in our projects. – Jarmila Jan 11 '21 at 16:08

0 Answers0